Closed KIMSEUNGGYU closed 2 years ago
react-notion-x
only supports ESM. The error is telling you to make sure that ESM is properly configured in your Jest config: https://jestjs.io/docs/ecmascript-modules
I recently find lots of people being confused about esm and cjs, here on this repo as well actually. Perhaps a short docs on this might be a good idea?
I solved it. Apply ESM to Jest
// jest.config.js
module.exports = createJestConfig(customJestConfig);
- **after**
// jest.config.js
module.exports = async () => ({ ...(await createJestConfig(customJestConfig)()), transformIgnorePatterns: ['node_modules/(?!(notion-client)/)'], });
- https://github.com/KIMSEUNGGYU/blog/pull/58/commits/0b653a81a3b28ee3b4e147fa83e1b4df3c563eae
Description
I use
@notionhq/client
andnotion/client
and testWhen testing
@notionhq/client
, it is performed Normally However, when testing thenotion/client
, the following error occurs.error messag
config
const createJestConfig = nextJest({ // Provide the path to your Next.js app to load next.config.js and .env files in your test environment dir: './', });
// Add any custom config to be passed to Jest const customJestConfig = { setupFilesAfterEnv: [ 'given2/setup', // '/jest.setup.js',
],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^@/components/(.)$': '/src/components/$1',
'^@/containers/(. )$': '/src/containers/$1',
'^@/pages/(.)$': '/pages/$1',
'^@/(. )$': '/$1',
},
testEnvironment: 'jest-environment-jsdom',
collectCoverageFrom: ['src/*/.{ts,tsx}', '!src/styles/*'], // coverage all file
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async module.exports = createJestConfig(customJestConfig);