1. TypeError: configSet.processWithEsbuild is not a function
Solution: Update jest.config.js to use jest-angular-preset instead of ts-preset.
1 | module.exports = { |
1 | module.exports = { |
2. SyntaxError: xxx.spec.ts: Missing semicolon. (26:42)
Look into the error message, the error occurs on this line.
1 | const compiled = fixture.nativeElement as HTMLElement; |
The reason is because as, it’s a keyword in TypeScript, but it’s not a keyword in JavaScript. So the root cause is Jest cannot understand the TypeScript syntax.
We need a preset to help Jest to understand TypeScript syntax. The ts-jest is the most popular one.
- If you project is a pure
TypeScriptproject, see here on how to configts-jest. - If you project is an
Angularproject, Please usejest-preset-angular, see here for details.
3. jest: failed to cache transform results in: xxx/jest/jest-transform-cache.map, Failure message: ENOSPC: no space left on device, write
This is because Jest is trying to transform itself, so add the following to your jest.config.js file will resolve this issue. see here for details.
1 | transformIgnorePatterns: [ |