Tests fail on dependency injection after upgrading to Angular 9
See original GitHub issueDescribe the Bug
Tests fail on components and services (and probably other things I have not yet tested) which have dependencies (in the constructor) after upgrading to Angular 9, with the following error:
TypeError: Cannot read property 'ɵprov' of undefined
Minimal Reproduction
-
create a project with the latest CLI version (currently 9.0.1)
-
setup the project following the guidelines from https://medium.com/angular-in-depth/angular-cli-ng-test-with-jest-in-3-minutes-v2-1060ddd7908d
-
create a service using the CLI
-
add a dependency to the service’s constructor (for instance HttpClient)
-
run ng test
-
test fails with the following error:
TypeError: Cannot read property 'ɵprov' of undefined
Adding HttpClientTestingModule
to TestBed imports makes no difference.
Minimal reproduction repo: https://github.com/bisonfoutu/jest-ng-9-issue
Expected Behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Environment
Libs
- @angular/core version: 9.0.0
- @angular-devkit/build-angular version: 0.900.1
- @angular-builders/jest version: 9.0.0-beta.3
For Tooling issues:
- Node version: 12.14.0
- Platform: Windows
Others:
Additional Context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Yes, I cloned, indeed there was a problem.
You need to set
"emitDecoratorMetadata": true
incompilerOptions
of yourtsconfig.spec.json
. Once you do this it starts working. More details here. I’ll update the article.I’m seeing this error as well, on tests for anything that has dependencies. And i do have
emitDecoratorMetadata
set to true. I didn’t at first, but then found this issue, and added it. But, it still has the same behavior.