【发布时间】:2019-05-24 21:30:59
【问题描述】:
我正在使用 JEST 对我的快速路线进行单元测试。
在运行 yarn test 时,我所有的测试用例都通过了,但我遇到了一个错误
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
我使用了async & done,但仍然抛出上述错误。
以下是我的规范代码。请帮忙
routes.spec.ts
const request = require('supertest');
describe('Test the root path', () => {
const app = require('./index');
test('GET /gql/gql-communication-portal/release-notes', async (done) => {
const response = await request(app).get('/gql/gql-communication-portal/release-notes');
expect(response.status).toBe(200);
done();
});
});
【问题讨论】:
-
app = require('./index')这会启动服务器侦听端口吗?理想情况下,应该设置您的服务器,以便无需实际启动它就可以导入它,这就是您在这种情况下想要做的。它也可能解决您的问题。 -
一定要记得看“问”的日期..
标签: typescript unit-testing express jestjs