ngneat / spectator

🦊 🚀 A Powerful Tool to Simplify Your Angular Tests
https://ngneat.github.io/spectator
MIT License
2.06k stars 178 forks source link

SyntaxError: Unexpected token 'export' #531

Open nikolas-nelson opened 2 years ago

nikolas-nelson commented 2 years ago

Trying to use spectator in my work project and when I run test (jest --watch ) I have this error:

Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • 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/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

/<root>/node_modules/@ngneat/spectator/jest/ngneat-spectator-jest.d.ts:5
export * from './public_api';
^^^^^^

SyntaxError: Unexpected token 'export'

  4 | import { State } from "../../store/reducers";
  5 |
> 6 | import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
    | ^
  7 |
  8 | describe("BasicInfoPageService", () => {
  9 |   let spectator: SpectatorService<BasicInfoPageService>;

I tried few things what I found but no luck. Any suggestions how to fix this?

Angular 12.1.1 Ngrx 12.2 nrwl/angular 12.7 nrwl/jest 12.7 babel-eslint 10.1 jest 27.0.3

Thank you!

Lonli-Lokli commented 2 years ago

You should add this to your jest.config.js

module.exports = {
  testPathIgnorePatterns: ['e2e'],
  preset: 'jest-preset-angular',
  transformIgnorePatterns: ['node_modules/(?!@angular|@ngneat|fp-ts)'],
  ...
};
nikolas-nelson commented 2 years ago

then I get TypeError: jest_1.createComponentFactory is not a function

guywou commented 2 years ago

same issue here...

gentoo90 commented 2 years ago

I had the same issue with angular-12 and spectator-11 and solved it by downgrading spectator to 8.3.2. I think it has something to do with the new angular package format. ng-packagr/ng-packagr@cc59146

dankerk commented 2 years ago

Is this an issue that will be fixed in any upcoming version of Spectator? I can't really introduce Spectator at my current company if we have to start using a version that's 3 major versions behind current. <3

mezmiro2040 commented 1 year ago

I ran into this bug as well. Adding the jest.config changes suggested earlier and downgrading to v8.3.2 resolved the export issue but caused other breaking changes.