我在使用jest进行api测试时遇到问题
目前的行为是什么?
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at ../../../../Users/chhoeurng.sakona/AppData/Roaming/npm/node_modules/jest-cli/node_modules/jest-jasmine2/build/queue_runner.js:68:21
我当前的代码
it ('GET should return a status of 200 OK', function (done) {
frisby
.get('url-api')
.expect('status', 200)
.done(done);
});
目前的行为是什么?
It should work normally and no error.
请提供您的确切Jest配置
I do not have configuration
在项目目录中运行npx envinfo --preset jest
并粘贴
结果
System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Binaries:
Node: 8.11.1
Yarn: Not Found
npm: 5.6.0
jest v22.4.3
答案 0 :(得分:0)
使用promises时,您需要返回一个promise或使用异步函数:
it ('GET should return a status of 200 OK', async() => {
await frisby
.get('url-api')
.expect('status', 200)
});
或
it ('GET should return a status of 200 OK', function () {
return frisby
.get('url-api')
.expect('status', 200)
});
另请查看docs