I'm using NextJS 12 and trying to test API Routes using Jest. When I try to do test I'm having issues with formidable which states:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import PersistentFile from './PersistentFile.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
This is my jest.config.js
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/', "node_modules/(?!variables/.*)"],
moduleNameMapper: {
'\\.(scss|sass|css)$': 'identity-obj-proxy',
},
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^modules/(.*)$': '<rootDir>/modules/$1'
},
preset: 'ts-jest',
testEnvironment: 'node',
transform: {}
};
I'm confused about how Typescript and Jest work in the latest NextJS 12. I usually use it in backend Nodejs commonjs