Closed toniton closed 1 year ago
Make sure your Jest setup supports ESM (ecmascript modules), it's not on by default
Thanks Paul, that worked. Adding this comment for future reference.
I resolved this issue using the following config:
jest.config.ts
/** @type {import('jest').Config} */
const config = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
useESM: true,
},
},
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
testEnvironment: 'node',
transformIgnorePatterns: ['/node_modules/(?!@noble)'],
};
module.exports = config;
ts.config.json
{
"compilerOptions": {
...
"resolveJsonModule": true,
"allowJs": true,
"esModuleInterop": true,
...
}
}
I'm am using
@noble/ed25519
in my NestJS application, and using Jest for unit test coverage.When running my test, I get the following error:
Package.json