错误:超时-异步回调未在5000毫秒内调用(由jasmine.DEFAULT_TIMEOUT_INTERVAL设置) [英] Error: Timeout - Async callback was not invoked within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

查看:164
本文介绍了错误:超时-异步回调未在5000毫秒内调用(由jasmine.DEFAULT_TIMEOUT_INTERVAL设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用茉莉花测试我的异步功能.我收到以下错误消息.

I am using jasmine to test my asynchronous function. I am getting following error.

错误:超时-异步回调未在5000毫秒内调用(由设置 jasmine.DEFAULT_TIMEOUT_INTERVAL)

Error: Timeout - Async callback was not invoked within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

我试图打印通过功能解析的数据.它正在控制台上打印,在那之后我出现了以上错误.

I tried to print data resolved from my function. It's printing on the console and after that i am getting above error.

funtion test(){
    return new Promise(funtion(resolve,reject){
        resolve({id:1})
    })
}

describe("test function",funtion(){
    it("testing",test().then(function(data,err){
        console.log("resolved Data = ",data)
        expect(data).toEqual({id:1}))
    }))
})

以上功能不是我的确切功能.这只是一个例子. 我正在获得CMD中数据的价值,然后我得到了

Above function is not my exact function. This is just an example. I am getting value of data in CMD, and after that i am getting

错误:超时-异步回调未在5000毫秒内调用(由设置 jasmine.DEFAULT_TIMEOUT_INTERVAL)

Error: Timeout - Async callback was not invoked within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

如果我的数据已经解决,那么为什么会出现此错误?

If my data is already resolved then why I am getting this error?

推荐答案

问题是您需要确保根据茉莉花标准完成测试.最简单的方法是使用done参数.就像这样:

The problem is that you need to ensure that the test is finished according to jasmine standards. The easiest way to do this is to use a done parameter. It would be like this:

describe("test function",funtion(){
    it("testing",done => {
        test().then(function(data,err){
            console.log("resolved Data = ",data)
            expect(data).toEqual({id:1}))
            done();
        }))
    })
})

您只需要确保在测试完成时调用done().

You just need to make sure that done() is invoked when the test is finished.

这篇关于错误:超时-异步回调未在5000毫秒内调用(由jasmine.DEFAULT_TIMEOUT_INTERVAL设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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