【发布时间】:2015-07-04 01:53:16
【问题描述】:
我已经在路由更改时创建了一个函数:
window.intercom = function(action, msg) {
return window.Intercom(action, msg);
};
我试图窥探这个功能,但不明白如何。我遵循了this SO post.中的建议
如果我使用这个:
beforeEach(inject(function($compile, $rootScope, $q, _$location_, $routeParams) {
element = angular.element("<add-box></add-box>");
$compile(element)($rootScope);
}));
it("should cancel adding a box!", function() {
spyOn(window, 'intercom')
});
我收到一个错误:
intercom() method does not exist
所以我尝试了这个:
it("should cancel adding a box!", function() {
var intercom = jasmine.createSpy();
});
上面写着:
TypeError: 'undefined' is not a function (evaluating 'window.intercom('hide')')
我怎样才能让它工作?我确定这很简单,我只是 Jasmine 的新手。
【问题讨论】:
-
请提供更多上下文。发送实际的测试代码。
-
@RobertMoskal 目前测试中没有太多其他内容,因为我只是想让它们运行。进行了一些更改。
标签: angularjs jasmine intercom.js