Skip to content

Instantly share code, notes, and snippets.

@raulb
Created February 20, 2012 04:17
Show Gist options
  • Save raulb/1867822 to your computer and use it in GitHub Desktop.
Save raulb/1867822 to your computer and use it in GitHub Desktop.
Fadeout test with Jasmine
// If we want to test Asynchronous events we should use waits or waitsFor
// To test a fadeOut effect, waits(num ms) could be ok, but is not too smart in my opinion
// more info: https://github.com/pivotal/jasmine/wiki/Asynchronous-specs
// What happens if we want to test if any element is correctly deleted but before of that the element is going into a fadeOut
// event?. Which is happening is its opacity is going to 0 but immediately of that the element is undefined.
// This is my way to do it:
it("If one element is deleted correctly", function() {
loadFixtures("fixtureContent.html");
expect($('#elements li').size()).toEqual(1);
$('#removeElement').click();
// Wait for fadeOut event finished
waitsFor(function() {
return (($('#elementToRemove').css('opacity') == 0) || $('#elementToRemove').css('opacity') == undefined);
}, "The element won't ever be hidden", 10000);
runs(function () {
expect($('#elements li').size()).toEqual(0);
});
});
@marcagas
Copy link

marcagas commented Jul 4, 2012

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment