angularjs - jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL -
i have angular service called 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 trying unit test 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(); }); });
i read asynchronous support in jasmine, rather new unit testing javascript couldn't make work.
i receiving error :
async callback not invoked within timeout specified jasmine.default_timeout_interval
and test taking long execute (about 5s).
can me providing working example of code explanation?
having argument in it
function cause attempt async call.
//this block signature trigger async behavior. it("should work", function(done){ //... }); //this block signature run synchronously it("should work", function(){ //... });
it doesn't make difference done
argument named, existence matters. ran issue copy/pasta.
the jasmin asynchronous support docs note argument (named done
above) callback can called let jasmine know when asynchronous function complete. if never call it, jasmine never know test done , timeout.
Comments
Post a Comment