Created
July 15, 2011 12:51
-
-
Save jareware/1084619 to your computer and use it in GitHub Desktop.
Waiting for a specific DOM event in 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
/** | |
* Pauses the tests execution until the named event is notified on the given | |
* element, or a timeout is reached. | |
* | |
* @param event | |
* @param onElement | |
* @param timeout | |
*/ | |
var waitsForEvent = function(event, onElement, timeout) { | |
timeout = timeout || 10000; | |
var eventFired = null; | |
waitsFor(function() { | |
if (eventFired === null) { | |
onElement.addEventListener(event, function() { | |
eventFired = true; | |
}, false); | |
eventFired = false; | |
} | |
return eventFired; | |
}, 'event "' + event + '" to fire on given element', timeout); | |
}; | |
// Usage example: | |
// waitsForEvent('load', iframe); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment