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