Cannot run Jest tests after
obaqueiro opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
When running npm run test
in a default NestJS project with TypeORM added, even empty tests do not run because of "unresolved dependencies"
Nest can't resolve dependencies of the AppService (?). Please make sure that the argument UserRepository at index [0] is available in the RootTestModule context.
Minimum reproduction code
https://github.com/obaqueiro/typeorm-tests-broken
Steps to reproduce
- Init a default NestJS project with
nest new test_project
- Add minimal TypeORM configuration (as shown in the linked minimum reproduction code)
- Run
npm start
to run the project, and verify that it is loading TypeORM correctly. - Run
npm run test
to try to run the tests.
Expected behavior
The tests should run correctly without error
Package version
8.0.3
NestJS version
8.0.0
Node.js version
16.14.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
I am trying to reproduce: #321 in a simple project, because in a larger project that's an error I am seeing, even though we are not using "absolute paths" for imports. However, while setting up the minimum runnable project I was unable to even run the tests due to this issue.
Your test setup is invalid. Your AppService
requires the @InjectRepository(User)
dependency, but it doesn't exist in the test module context.
Please use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.
But this actually happens even before loading any test. The test code is actually EMPTY so nothing is being run. It is not even requiring any files.
Note that this is not the e2e tests, but the unit tests, which are completely empty.
The Test.createTestingModule().compile()
is told to make a module using controllers: [AppController]
and providers: [AppService]
. Nest tries to make the AppService
and finds out it can't because there's no match for @InjectRepository(User)
m like I already said.
Now please , for further support use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.