我很难创造茉莉花间谍。角1.5分量与电流的结合:&。我希望检测何时调用通知函数中的分页函数。
测试
beforeEach(inject(function ($rootScope, _$componentController_) {
model = {
min: 1,
max: 10,
current: 1,
notify: function () {
return function paging(page){console.log(page);}
}
};
$componentController = _$componentController_;
}));
it('will not page forward on page 10', function () {
model.current = 10;
pager.pageForward();
expect(model.current).toBe(10);
});组件片段
model.pageFoward() {
model.notify()(model.current);
}发布于 2016-06-01 05:31:40
在这种情况下,您不需要监视,您应该创建一个间谍并返回到model.notify中。尝试:
var notifyReturnFunction;
...
notifyReturnFunction = jasmine.createSpy('notifyReturnFunction');
model = {
min: 1,
max: 10,
current: 1,
notify: function() {
return notifyReturnFunction;
}
};
...现在您可以断言它已被调用:
it('will not page forward on page 10', function () {
model.current = 10;
pager.pageForward();
expect(model.current).toBe(10);
expect(notifyReturnFunction).toHaveBeenCalled();
// Or
expect(notifyReturnFunction).toHaveBeenCalled(model.current);
});https://stackoverflow.com/questions/37532362
复制相似问题