我在nestjs上进行测试时遇到了奇怪的问题。
运行npm run test
时,大多数测试均失败。一些变量变得不确定,nest无法解析依赖关系等。
但是,当我从WebStorm面板运行ALL TESTS
时,一切正常。
https://gist.github.com/hejkerooo/5a56ee2a7d78ce41cb390d1ece648933
Nest can't resolve dependencies of the TrendService (?). Please make sure that the argument at index [0] is available in the _RootTestModule context.
at Injector.lookupComponentInExports (node_modules/@nestjs/core/injector/injector.js:180:19)
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at mapper (node_modules/jest-jasmine2/build/queueRunner.js:25:45)
TypeError: Cannot read property 'clear' of undefined
17 | beforeEach(async () => {
18 | jest.restoreAllMocks();
> 19 | await trendsRepository.clear();
| ^
20 | });
21 |
22 | afterAll(async () => {
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
(node:2633) UnhandledPromiseRejectionWarning: TypeError: Caught error after test environment was torn down
答案 0 :(得分:-2)
该问题已解决-刚刚在jest.setTimeout
到50000
之间使用过,工作正常。
我认为这是一个临时解决方案,但会深入研究它。