This repository was archived by the owner on Oct 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
This repository was archived by the owner on Oct 15, 2025. It is now read-only.
Not working with an Angular 7 project? #2
Copy link
Copy link
Closed
Description
Describe the bug
With the latest from Angular (cli, core, etc) in v7 it seems to be broken.
The error is:
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/home/maxime/Desktop/ng-with-jest/src/app/app.component.spec.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { TestBed, async } from '@angular/core/testing';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
To Reproduce
Steps to reproduce the behavior:
- Create a new project using CLI v7
- Add Material or another lib to have some imports
- Launch jest
Desktop (please complete the following information):
- OS: [e.g. Mac, Windows]: Ubuntu
- Node version: [e.g. 8.11.3]: 10.12
- NPM or Yarn version [e.g. Yarn 1.3.0]: yarn v1.10.1
- App type [e.g. Angular CLI, Nx Workspace] Angular CLI
- Angular version [e.g. @angular/core: "6.0.3"] 7
PS:
this might be related to https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother but tried and couldn't get it working...
Metadata
Metadata
Assignees
Labels
No labels