I can successfully run a jest test for a component that uses the import
command IF I am importing from a relative path or from node_modules. So, this is working for my.component.spec.ts:
import {MyComponent} from './my.component';
import {createComponentFactory, Spectator} from '@ngneat/spectator/jest';
In my component template, I want to make use of some shared pipes that are part of another library within the project. Ideally, it would look like this:
import {SharedPipesModule} from '@my-project/shared/pipes';
However, this fails with:
Cannot find module '@my-project/shared/pipes' from ...
I've tried using this in the tsconfig.spec.json, but it did not make a difference.
"paths": {
"@my-project/shared/pipes": ["libs/shared/pipes/src/index.ts"]
}
I am using Jest v26 and Angular 10. How can I get the test to successfully import the module I need?
In my package.json, I have:
"@babel/preset-env": "^7.12.1",
"@types/jest": "^26.0.0",
"babel-jest": "^26.0.0",
"jest": "^26.0.0",
"jest-marbles": "^2.0.0",
"jest-preset-angular": "^8.0.0",
"ts-jest": "^26.0.0",