Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Jest failed to parse a file in Angular 14 #1839

Open
jesusmsr opened this issue Nov 22, 2022 · 3 comments
Open

[Bug]: Jest failed to parse a file in Angular 14 #1839

jesusmsr opened this issue Nov 22, 2022 · 3 comments

Comments

@jesusmsr
Copy link

Version

12.2.2

Steps to reproduce

I'm having this issue in a project generated with Angular 11 and updated to Angular 14, but I managed to reproduce it in a project generated with Angular 13 and updated to Angular 14.
I did my research before creating this bug report, but all I've tried did not work for me.

  1. Clone my repo https://github.com/jesusmsr/jest-angular-14-report.git
  2. npm install
  3. npm run test

Expected behavior

Test should run

Actual behavior

Tests fail and this error is shown:
imagen

Additional context

I tried changing the module in tsconfig to CommonJs, setting up ts-jest, changing transform setting in jest.config, and a number of different things I have found online.
I have not been able to find a solution that works to me. I've also followed this guide: https://thymikee.github.io/jest-preset-angular/docs/guides/angular-13+/

Environment

# package.json
"dependencies": {
    "@angular/animations": "^14.2.10",
    "@angular/cdk": "^14.2.7",
    "@angular/common": "^14.2.10",
    "@angular/compiler": "^14.2.10",
    "@angular/core": "^14.2.10",
    "@angular/forms": "^14.2.10",
    "@angular/platform-browser": "^14.2.10",
    "@angular/platform-browser-dynamic": "^14.2.10",
    "@angular/router": "^14.2.10",
    "rxjs": "~7.4.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.9",
    "@angular/cli": "^14.2.9",
    "@angular/compiler-cli": "^14.2.10",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.10.0",
    "jest": "^29.3.1",
    "jest-preset-angular": "^12.2.2",
    "karma-coverage": "~2.1.0",
    "typescript": "~4.8.4"
  }
@ahnpnl
Copy link
Collaborator

ahnpnl commented Nov 22, 2022

You can check this

rxjs: '<rootDir>/node_modules/rxjs/dist/bundles/rxjs.umd.js',

our example folder contains basic setup which works for most of projects.

The error is about jest doesn’t understand the file and we need to explicitly tell Jest to transform it

@jesusmsr
Copy link
Author

jesusmsr commented Nov 23, 2022

I actually looked at that example before, but somehow missed that. My bad.
I added that to my jest.config and one test passes, but I have two more tests in which I import components from a library in which I get the following error: TypeError: Class extends value undefined is not a constructor or null
File is a .mjs file, and the exact line which gives the error is this: class DsAnimationFrameScheduler extends AsyncScheduler

In the test that passes, there are no components from this library

Edit: AsyncScheduler is part of rxjs

@jbjhjm
Copy link

jbjhjm commented Dec 19, 2022

Very likely related to #1199
typescript 4.8 currently is a problem.
In your case, ng14 can be used with ts 4.7.
Downgrade and you should be fine for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants