Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Evented/Timed test helpers #121
DISCLAIMER: most of the ideas here may be project specific but appear, at least from where I'm standing, to be useful in a myriad of scenarios when testing event based functionality.
Timing and event based tests in QUnit and other frameworks tend to be fragile and even dependent on execution order in practice. There are few test helpers that we've found to be invaluable in working with events and time dependent functionality.
sequence( functions, timeout )
Many tests that require a set of timeouts to verify functionality can be cleaned up by abstracting multiple calls to setTimeout into a single helper. This is just as brittle as using the timeouts themselves but at least results in cleaner code where no event is provided to guarantee the behavior.
eventSequence( event, functions )
The event sequence helper executes a list of functions based on a series of the same event firing to trigger each. The most obvious use case where jQuery Mobile is concerned is page transitions which fire the
An example from the event tests:
An example from the navigation tests.
eventCascade( event, function, event, function ... )
We haven't stumbled upon a use case here yet but it seems likely that a more flexible form of the eventSequence function would be valuable. In fact this should encourage a more pluggable design since events will be the preferred way to guarantee states of execution in the code being tested!
Jasmine has a nice helper in the form of