I am covering this part of system with tests at the moment, I have events chained in a way that stopping propagation on first must cancel second event from firing.
$.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);
}
}
}
});
I figured how to check that second event was fired with 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();
});
but now I need to test the case where propagation is being stopped and second event is not being fired.
How to check if event has not been fired?
There is not
property on Jasmine expect
that allows to invert the check.
Code below worked for me.
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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With