I have found a problem testing JQuery animations. The problem is that during jasmine.Clock.useMock()
mode JQuery does not call complete
function after effect execution.
Logic:
$('#mydiv').fadeOut('normal', function () {
// this is called AFTER the test ends
// but should be called after jasmine.Clock.tick(1000);
$(this).remove();
})
Spec:
it('should pass', function () {
jasmine.Clock.useMock();
// call logic
jasmine.Clock.tick(1000);
// using jasmine-jquery matcher
expect($('#mydiv')).not.toExist();
})
Test fails with the message:
Expected '<div id="mydiv" style="opacity: 0; "></div>' not to exist.
It means that effect ended correctly, but complete
function was not called. It actually gets called after test runner finishes execution.
I am not sure whether it is bug to be reported to JQuery or to Jasmine developers. Maybe someone would suggest workaround.
My goal is to test that element was removed after the logic execution, so I need not.toExist()
matcher.
I'm the 0.00001%, as I'm using backbone with prototype - but I added this to my SpecHelper.js file to get around the scriptaculous effects I'm using and ensure my callbacks are executed.
I'm sure you could take the same approach for jquery.