asyncTest()


asyncTest( name, test )

Description: Add an asynchronous test to run. The test must include a call to start().

For testing asynchronous code, asyncTest will automatically stop the test runner and wait for your code to call start() to continue.

This method used to have an optional second argument called expected. This argument is deprecated and its usage will start throwing errors in 2.0.0. If you're using it, use expect() instead.

Examples:

Example: The following illustrates an asynchronous test that waits 1 second before resuming

1
2
3
4
5
6
7
8
asyncTest( "asynchronous test: one second later!", function() {
expect( 1 );
setTimeout(function() {
ok( true, "Passed and ready to resume!" );
start();
}, 1000);
});

Example: A more practical example that must wait for a video element to be loaded before running any assertions.

1
2
3
4
5
6
7
8
9
asyncTest( "asynchronous test: video ready to play", function() {
expect( 1 );
var $video = $( "video" );
$video.on( "canplaythrough", function() {
ok( true, "video has loaded and is ready to play" );
start();
});
});