【发布时间】:2019-03-13 01:29:18
【问题描述】:
这是我的 HTTP 路由
app.get('/', (req, res) => {
res.status(200).send('Hello World!')
})
app.post('/sample', (req, res) => {
res.status(200).json({
x:1,y:2
});
})
我想测试以下内容
1) GET 请求工作正常。
2)/sample 响应包含属性和x 和y
const request = require('supertest');
const app = require('../app');
describe('Test the root path', () => {
test('It should response the GET method', () => {
return request(app).get('/').expect(200);
});
})
describe('Test the post path', () => {
test('It should response the POST method', (done) => {
return request(app).post('/sample').expect(200).end(err,data=>{
expect(data.body.x).toEqual('1');
});
});
})
但我在运行测试时遇到以下错误
Jest 检测到以下 1 个可能保留 Jest 的打开句柄 从退出:
返回请求(app).get('/').expect(200);
【问题讨论】:
标签: javascript express testing jestjs