Created
February 20, 2012 04:17
-
-
Save raulb/1867822 to your computer and use it in GitHub Desktop.
Fadeout test with Jasmine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}); |
Sure you could remove it using the fadeOut
callback (that's the right way to do it). Since the scope of this code is a spec, the idea under waitsFor
is testing that you're doing it right.
More info about asynchronous specs here: https://github.com/pivotal/jasmine/wiki/Asynchronous-specs
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you explain clearly what does the waitsFor do? could i remove the element inside the waitsFor function? cause what I did in my fadeOut callback is to remove the element