我正在尝试通过 Nest 测试一个课程。在这个类中(参见下图),对该类进行编码的人通过 typeorm 创建一个存储库。
当我尝试测试“createContact”函数时,出现以下错误:“Nest 无法解析 ContactService 的依赖项(?)。请确保索引 [0] 处的参数 ContactRepository 在 AuthModule 上下文中可用”。
这是我的测试课:
您知道如何使测试考虑到这一点,从而不再出现错误吗?
我尝试按照本教程为我的项目设置 jest:https : //dev.to/nedsoft/testing-nodejs-express-api-with-jest-and-supertest-1km6
但是,当我尝试运行基本测试时,出现以下错误:
FAIL tests/sample.test.js
? Test suite failed to run
ReferenceError: describe is not defined
> 1 | describe('Sample Test', () => {
| ^
2 | it('should test that true === true', () => {
3 | expect(true).toBe(true)
4 | })
at Object.<anonymous> (tests/sample.test.js:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.521 s
Ran all test suites.
(node:15452) ExperimentalWarning: The fs.promises API is experimental
npm ERR! Test failed. See …Run Code Online (Sandbox Code Playgroud)