jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时时间内未调用异步回调 [英] Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

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

问题描述

我正在使用主干访存调用来访存数据.当我尝试使用茉莉花对其进行测试时,出现错误错误:超时-异步回调未在jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时内调用.

I am fetching the data using the backbone fetch call. When I tried to test it using the jasmine, I got an error as Error: Timeout - Async callback was not invoked within the timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

当我控制台valueReturned时,它将为我提供所需的实际值.响应中没有错误.但是,我在页面上遇到的唯一问题是上面指定的超时错误.

When I console the valueReturned it provides me the actual value which I need. There is no error in the response. But the only thing which I get on my page is timeout error which I specified above.

您能告诉我我在做什么错吗?

Can you please let me know what I am doing wrong?

describe("fetch call", function() {
var valueReturned;
beforeEach(function(done) {
    window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
    setTimeout(function () {
    todoCollectionCursor.fetch({
        success : function(collection, response, options) {
            valueReturned = options.xhr.responseText; 
            return valueReturned;
        }
    });
    },500);
});

it("should return string", function(done) {
       console.log(valueReturned);
       expect(typeof valueReturned).toEqual('string');
});
});

推荐答案

我找到了答案.由于它是一个Ajax调用,因此我应该模拟该请求.我在jasmine-Ajax下找到了它- https://github.com/jasmine/jasmine-ajax

I found the answer for it. Since it is an Ajax call I should mock the request. This I found under jasmine-Ajax - https://github.com/jasmine/jasmine-ajax

it("Response check response when you need it", function() {

              var doneFn = jasmine.createSpy("success");
              $.ajax({
                 url: '/fetch',
                 method: 'GET',
                 success : function(data)
                 {
                     doneFn(data);
                 }
              })
          jasmine.Ajax.requests.mostRecent().respondWith({
                "status": 200,
                "contentType": 'text/plain',
                "responseText": '[{title:"Aravinth"}]'
           });
          expect(jasmine.Ajax.requests.mostRecent().responseText).toEqual('[{title:"Aravinth"}]');
   });

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

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