gpt4 book ai didi

api - 超时 - 在 jest.setTimeout 指定的 5000 毫秒超时时间内未调用异步回调

转载 作者:行者123 更新时间:2023-11-28 20:13:44 26 4
gpt4 key购买 nike

我在使用 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);
});

当前的行为是什么?应该可以正常运行,没有报错。

请提供您确切的 Jest 配置我没有配置

在您的项目目录中运行 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

最佳答案

当使用 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

关于api - 超时 - 在 jest.setTimeout 指定的 5000 毫秒超时时间内未调用异步回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49725389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com