获得超时-在jest.setTimeout指定的5000ms超时内未调用异步回调 [英] Got Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout

查看:671
本文介绍了获得超时-在jest.setTimeout指定的5000ms超时内未调用异步回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开玩笑地进行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

解决方案

唤醒诺言时,您需要返回诺言或使用异步函数:

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)

    });

还可以查看文档

I have problem with api-testing with jest

What is the current behavior?

 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

My current code

it ('GET should return a status of 200 OK', function (done) {
        frisby
            .get('url-api')
            .expect('status', 200)
            .done(done);
    });

What is the current behavior? It should work normally and no error.

Please provide your exact Jest configuration I do not have configuration

Run npx envinfo --preset jest in your project directory and paste the results here

 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

解决方案

You need to return a promise or use an async function when woking with promises:

it ('GET should return a status of 200 OK', async() => {
        await frisby
            .get('url-api')
            .expect('status', 200)

    });

or

it ('GET should return a status of 200 OK', function () {
        return frisby
            .get('url-api')
            .expect('status', 200)

    });

Also have a look at the docs

这篇关于获得超时-在jest.setTimeout指定的5000ms超时内未调用异步回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆