I have a small test (Jasmine + jasmine-jquery) to check if a btn have been clicked and test if its callbacks were correctly executed, but I am facing some strange errors:
Here is the test:
it("Check if pagination arrows/btns had been clicked", function() {
// beforeEach to spy on callbacks:
beforeEach(function() {
spyOn(comp, "_pageUp");
});
var arrowUp = $('.arrow-up').eq(0);
var spyEvent = spyOnEvent(arrowUp, 'click');
// Trigger the event:
$(arrowUp).click();
expect('click').toHaveBeenTriggeredOn(arrowUp);
expect(spyEvent).toHaveBeenTriggered();
// Check if the click callback was correctly called:
expect(comp._pageUp).toHaveBeenCalled();
});
The comp
variable is a JS Object. What I want is, when its $('.arrow-up').eq(0);
button gets clicked, the _pageUp method is called. After that, there are the tests to those methods (comp._pageUp()
and comp._pageDown()
).
The error message I have is:
Expected event [object Object] to have been triggered on [object Object]
Also, a last reminder: I am pretty sure the fixture is corrected loaded and the test is running after the window.onload event.
Could someone help me understand what am I doing wrong?
Thank you, guys.