I have an 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 am trying to execute 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(); }); });
I read about asynchronous support in Jasmine, but since I'm pretty new to unit testing with javascript, I couldn't get it to work.
I get an error message:
Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
and my test is too long to complete (about 5 seconds).
Can someone help me provide a working example of my code with some explanation?
debugging angularjs asynchronous unit-testing jasmine
Mdb Mar 24 '14 at 8:48 2014-03-24 08:48
source share