我有一個(gè)叫的服務(wù)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 };});我正在嘗試使用茉莉花對(duì)該服務(wù)進(jìn)行單元測(cè)試:"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(); });});我閱讀了有關(guān)Jasmine中的異步支持的信息,但是由于我對(duì)使用JavaScript進(jìn)行單元測(cè)試相當(dāng)陌生,因此無法使其正常工作。我收到一個(gè)錯(cuò)誤:Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL而且我的測(cè)試執(zhí)行時(shí)間太長(zhǎng)(大約5秒)。有人可以幫助我提供一些可行的代碼示例嗎?
- 3 回答
- 0 關(guān)注
- 1234 瀏覽
添加回答
舉報(bào)
0/150
提交
取消