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

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

问题描述

我在使用 jest 进行 api 测试时遇到问题

目前的行为是什么?

 超时 - 在 jest.setTimeout 指定的 5000 毫秒超时内未调用异步回调.在 ../../../../Users/chhoeurng.sakona/AppData/Roaming/npm/node_modules/jest-cli/node_modules/jest-jasmine2/build/queue_runner.js:68:21

我当前的代码

it ('GET 应该返回 200 OK 的状态', function (done) {弗里斯比.get('url-api').expect('状态', 200).完成(完成);});

目前的行为是什么?它应该可以正常工作,没有错误.

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

在项目目录中运行 npx envinfo --preset jest 并粘贴结果在这里

 系统:操作系统:Windows 10CPU:x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz二进制文件:节点:8.11.1纱线:未找到npm:5.6.0开玩笑 v22.4.3

解决方案

使用 promise 时需要返回 promise 或使用异步函数:

it ('GET 应该返回 200 OK 的状态', async() => {等待弗里斯比.get('url-api').expect('状态', 200)});

it ('GET 应该返回 200 OK 的状态', function () {返回弗里斯比.get('url-api').expect('状态', 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

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

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