我用测试atm来覆盖系统的这一部分,我的事件链接的方式是首先停止传播必须取消第二个事件才能解雇。
$.fn.extend({
OnTheMoveBCTrigger: function (name, options) {
if (!(this[0] instanceof OnTheMove_BusinessComponent)) {
throw ('is not an instance of OnTheMove_BusinessComponent');
} else {
var event = $.Event(name);
var promise = $(this).OnTheMoveTrigger(event, options);
if (!event.isPropagationStopped()) {
$(onTheMove.PageDataRoles).OnTheMoveTrigger(name, options);
}
}
}
});
我想了解如何使用jasmine-jquery spyOnEvent
it("OnTheMoveBCTrigger chain fires event on onTheMove.PageDataRoles", function () {
var spy = spyOnEvent(onTheMove.PageDataRoles, 'event2');
$(window.bc).OnTheMoveBCTrigger("event2");
expect('event2').toHaveBeenTriggeredOn(onTheMove.PageDataRoles);
expect(spy).toHaveBeenTriggered();
});
但现在我需要测试传播正在停止而第二个事件没有被触发的情况 如何检查事件是否未被触发?
答案 0 :(得分:1)
Jasmine not
上有expect
属性,允许反转支票
下面的代码对我有用。
it("OnTheMoveBCTrigger does NOT chain fire event on onTheMove.PageDataRoles, if propogation is stopped on BC event.", function () {
var spy = spyOnEvent(onTheMove.PageDataRoles, 'event3');
$(window.bc).on("event3", function (e) {
e.stopPropagation();
});
$(window.bc).OnTheMoveBCTrigger("event3");
expect('event3').not.toHaveBeenTriggeredOn(onTheMove.PageDataRoles);
expect(spy).not.toHaveBeenTriggered();
});