【发布时间】:2022-06-10 22:37:52
【问题描述】:
我想知道如何测试我的端点,因为我每次尝试都会收到TypeError: app.address is not a function。
代码:
app.use('api/test', (req, res) => {
res.status(200).json("hello world")
});
测试代码:
app.use('api/test', (req, res) => {
res.status(200).json("hello world")
});
This the error I get after attempting to run the test:
FAIL ./server.test.js
User manager API
× GET /api/test --> get error (2 ms)
● User manager API › GET /api/test --> get error
TypeError: app.address is not a function
5 | it('GET /api/test --> get error', async () => {
6 | return await request(app)
> 7 | .get('/api/test')
| ^
8 | .expect('Content-Type', /json/)
9 | .expect(200)
10 |
at Test.serverAddress (node_modules/supertest/lib/test.js:46:22)
at new Test (node_modules/supertest/lib/test.js:34:14)
at Object.obj.<computed> [as get] (node_modules/supertest/index.js:28:14)
at Object.get (server.test.js:7:8)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.974 s
Ran all test suites.
【问题讨论】:
-
我在这里看到一个错字 .get('/api/accownts/')
-
这里缺少很明显的东西,你不觉得吗?请提供minimal reproducible example 允许其他人重新创建问题。你研究过错误信息吗?
-
@mak15 这可能是一个错字,但随后测试可能会通过(因为它预计会出现 404)。
-
抱歉,上传时遇到问题,不得不编辑
标签: node.js mongodb express jestjs supertest