我在 server.test.js 上有一個簡單的設定
import 'regenerator-runtime/runtime';
const request = require('supertest');
const express = require("express")
const app = express();
app.get('/user', function(req, res) {
res.status(200).json({ name: 'john' });
});
describe('GET /user', function() {
it('responds with json', async function(done) {
const response = await request(app)
.get('/user')
expect(response.status).toBe(201)
})
})
npx jest并且接收thrown: "Exceeded timeout of 5000 ms for a test.,增加的超時在 jest.config.js 中對 testTimeout: 20000 沒有幫助,它等待 20 秒并且也失敗
為什么快遞應用以超集開頭?我使用了官方 README 中的示例
uj5u.com熱心網友回復:
嘗試done從測驗回呼中洗掉:
it('responds with json', async function() {
const response = await request(app)
.get('/user')
expect(response.status).toBe(201)
})
Jest 可能正在等待它被呼叫。
通常建議您使用async函式或done. 如果你混合它們,Jest 通常會發出警告,不知道為什么它不會在這個設定中這樣做。
或者,您可以嘗試done()在測驗結束時呼叫。
您應該期望測驗失敗,因為發布的狀態是200并且您正在檢查201.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/363253.html
標籤:javascript 节点.js 表达 玩笑 超级测试
下一篇:如何將webhook指向前端
