[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
There doesn't appear to be any documentation on how to import Services, Models (TypeORM) or Repositories from other modules in nest.js. The auto completion in Visual Studio Code works for running the application.
import { Base } from 'common/model/Base.model';
However when you run tests in ts-jest, we always get the following error.
Cannot find module 'common/model/Base.model' from 'Event.model.ts'
Changing the import to a relative path below fixes the issue.
import { Base } from '../../common/model/Base.model';
but is this the right way to do this?
import { Base } from 'common/model/Base.model';
should satisfy both Nest.js and ts-jest tests.
Create an application and a module called common
and another called events
// common/model/Base.model.ts
export abstract class Base {
id: number;
created: Date;
updated: Date;
}
// events/model/Event.model.ts
import { Base } from 'common/model/Base.model';
export class Event extends Base {}
// events/model/Event.model.spec.ts
import { Event } from './event.model';
describe('EventModel', () => {
it(`This doesn't work`, () => {
const event = new Event();
expect(event).not.toBeUndefined();
});
})
Run yarn test
So that my tests pass, and there's clear documentation on how to ensure that ts-jest and Nest.js work together.
Nest version: 5.0.0-beta.6
For Tooling issues:
- Node version: v10.4.1
- Platform: Mac, running Docker - gcr.io/google-appengine/nodejs
Others:
No
I managed to resolve this by setting the jest.modulePaths
property in package.json to ["<rootDir>"]
```
{
...
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"modulePaths": ["
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\.(t|j)s$": "ts-jest"
},
"mapCoverage": true,
"coverageDirectory": "../coverage"
}
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I managed to resolve this by setting the
jest.modulePaths
property in package.json to["<rootDir>"]
```"],
{
...
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"modulePaths": ["
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\.(t|j)s$": "ts-jest"
},
"mapCoverage": true,
"coverageDirectory": "../coverage"
}
}