I have a simple function which fades in an element:
CODE
checkLengthSelect: function(){
if($(this).val() != ''){ // if not empty
$('.c--error').fadeOut('fast', function(){
$('#button').fadeIn();
})
} else { // if empty hide button and show error message
$('#button').fadeOut('fast', function(){
$('.c--error').html('foo').fadeIn(); // <-- I want to test this on fadeOut callback
})
}
},
I'm trying to write a test for it like this:
TEST
it("it should have a value or hide continue button", function(){
// check cover length on select
$(document).on('change', '#select', function(){ qqw.validate.checkLengthSelect.call(this) } );
// force a change event to fire with empty value.
$('#select').val('').change();
setTimeout(function(){
expect($('.c--error').html()).toEqual('foo');
done(); // <-- test if done
}, 800);
});
ERROR
This shows in console
'expect' was used when there was no current spec, this could be because an asynchronous test timed out
QUESTION
How can I test that an event happens when the fadeOut
completes?
I'm using Jasmine v2+