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

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

问题描述

我有一个名为角服务 requestNotificationChannel

app.factory("requestNotificationChannel", function($rootScope) {

    var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_";

    function deleteMessage(id, index) {
        $rootScope.$broadcast(_DELETE_MESSAGE_, { id: id, index: index });
    };

    return {
       deleteMessage: deleteMessage
    };

});

我是用茉莉花试图单元测试这项服务:

I am trying to unit test this service using jasmine:

"use strict";

describe("Request Notification Channel", function() {
    var requestNotificationChannel, rootScope, scope;

    beforeEach(function(_requestNotificationChannel_) {
        module("messageAppModule");

        inject(function($injector, _requestNotificationChannel_) {
            rootScope = $injector.get("$rootScope");
            scope = rootScope.$new();
            requestNotificationChannel = _requestNotificationChannel_;
        })

        spyOn(rootScope, '$broadcast');
    });


    it("should broadcast delete message notification", function(done) {

        requestNotificationChannel.deleteMessage(1, 4);
        expect(rootScope.$broadcast).toHaveBeenCalledWith("_DELETE_MESSAGE_", { id: 1, index: 4 });
        done();       
    });
});

我看了一下异步支持的茉莉花,但因为我是相当新的用JavaScript单元测试不能使它工作。

I read about the Asynchronous Support in Jasmine, but as I am rather new to unit testing with javascript couldn't make it work.

我收到一个错误:

Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

和我的测试时间太长来执行(约5秒)。

and my test is taking too long to execute (about 5s).

有人可以帮我提供工作的例子我的code的一些解释呢?

Can somebody help me providing working example of my code with some explanation?

推荐答案

有在争论你的函数将导致它尝试一个异步调用。

Having an argument in your it function will cause it to attempt an async call.

   //this block signature will trigger async behavior.
it("should work", function(myarg){
  //...
});

   //this block signature will run synchronously
it("should work", function(){
  //...
});

它不会有所作为什么 myarg 参数被调用。它的存在是最重要的。我遇到了此问题太多拷贝/面食

It doesn't make a difference what the myarg argument is called. Its existence is all that matters. I ran into this issue from too much copy/pasta

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

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