Jest Service Inject Error after v12 upgrade #6097
Labels
blocked: third-party
outdated
scope: testing tools
Issues related to Cypress / Jest / Playwright / Vitest support in Nx
type: bug
Current Behavior
Assume you have a simple service:
MyService
, along with potentially many other services logically belonging together. They all reside in a folder called "my-services" and all get individually exported via an index.ts in that folder.Assume you have then added an index.ts in the parent folder to group and re-export those services under a common moniker like so:
Your component now injects the service as follows:
This provides no problem for Angular at all and works during dev and prod builds as expected.
Before the v12 upgrade this was also not a problem for running tests.
Now, however, the service can no longer be resolved during test runs. The produced error is:
Importing the Service directly into the component (by not using the re-export) the test runs fine.
Expected Behavior
Tests run fine no matter how a dependency is imported.
Steps to Reproduce
/apps/jest-problem/src
my-service.ts
to that folder containing:AppComponent
via constructor injection using the "namespace":Here is a Github repo that shows the issue with the above steps already implemented:
https://github.com/Jejuni/jest-problem-repro
Failure Logs
FAIL jest-problem apps/jest-problem/src/app/app.component.spec.ts
AppComponent
× should create the app (43 ms)
● AppComponent › should create the app
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.535 s
Ran all test suites matching /jest-problem-repro\apps\jest-problem\src\app\app.component.spec.ts/i with tests matching "AppComponent".
Environment
NxReport
Node : 14.15.3
OS : win32 x64
npm : 6.14.9
nx : Not Found
@nrwl/angular : 12.4.0
@nrwl/cli : 12.4.0
@nrwl/cypress : 12.4.0
@nrwl/devkit : 12.4.0
@nrwl/eslint-plugin-nx : 12.4.0
@nrwl/express : Not Found
@nrwl/jest : 12.4.0
@nrwl/linter : 12.4.0
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.4.0
@nrwl/web : Not Found
@nrwl/workspace : 12.4.0
@nrwl/storybook : 12.4.0
@nrwl/gatsby : Not Found
typescript : 4.2.4
The text was updated successfully, but these errors were encountered: