I am wanting to ensure that a object's method gets called as an event handler, when a custom jQuery event is triggered; but the unit test is seemingly returning a false-negative, as my implementation works well.
(This is part of a test suite that uses Twitter Flight & the Flight Jasmine extensions, but this is just a vanilla Jasmine spy.)
describe('listening for uiNeedsPlan event', function() {
var spy;
beforeEach(function() {
spy = spyOn(this.component, 'getPlan');
$(document).trigger('uiNeedsPlan');
});
it('gets the current plan', function() {
expect(spy).toHaveBeenCalled();
});
});
This results in a failed spec:
Expected spy getPlan to have been called.
Here is a snippet from my code implementation of my Flight component (which works successfully):
this.after('initialize', function () {
this.on(document, 'uiNeedsPlan', this.getPlan);
});