I migrated an Angular project from Jasmine to Jest following this migration guide. Despite following the steps, I’m encountering multiple issues where Jest fails to parse my TypeScript test files, citing missing arguments and module resolution errors. I’ve ensured that my Jest setup is configured as recommended for an Angular TypeScript environment.
Here are some of the errors I’m receiving:
node_modules/@types/jest/index.d.ts:1580:48
function createSpyObj<T>(baseName: string, methodNames: any[]): T;
An argument for 'methodNames' was not provided.
src/app/scrum/scrum-user/scrum-user.component.spec.ts:14:37 - error TS2554: Expected 2 arguments, but got 1.
14 const teamsServiceSpy = jasmine.createSpyObj<TeamsService>(['getAllTeams']);
Cannot find module 'src/environments/environment' from 'src/app/scrum/scrum.service.ts'
Here is my jest.config.js setup:
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/src/setup-jest.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json'
}
},
transform: {
'^.+\.ts$': 'ts-jest'
},
moduleNameMapper: {
'^@app/(.*)$': '<rootDir>/src/app/$1',
'^@assets/(.*)$': '<rootDir>/src/assets/$1',
'^@env$': '<rootDir>/src/environments/environment'
}
};
What might be causing the module resolution errors, and how can I resolve them?
Any guidance or insights would be greatly appreciated as I work through these migration challenges.
R Th is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.