Created
January 3, 2011 23:18
-
-
Save cowboy/764161 to your computer and use it in GitHub Desktop.
QUnit: multiple async tests in one test
This file contains hidden or 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
| // Don't do this! Why? It will wait for two seconds, regardless. | |
| asyncTest( "multiple async w/ setTimeout", function() { | |
| expect( 4 ); | |
| var url = "http://jsfiddle.net/echo/jsonp/?callback=?"; | |
| $.getJSON( url, { a: 1 }, function( data ) { | |
| ok( data, "data is returned from the server" ); | |
| equal( data.a, "1", "the value of data.a should be 1" ); | |
| }); | |
| $.getJSON( url, { b: 2 }, function( data ) { | |
| ok( data, "data is returned from the server" ); | |
| equal( data.b, "2", "the value of data.b should be 2" ); | |
| }); | |
| setTimeout( start, 2000 ); | |
| }); |
This file contains hidden or 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
| // While the timeout is set for two seconds, the test may continue before that. | |
| test( "multiple async w/ counter", function() { | |
| expect( 4 ); | |
| stop( 2000 ); | |
| // Only call start() when counter is 0. | |
| var counter = 2; | |
| function done() { --counter || start(); } | |
| var url = "http://jsfiddle.net/echo/jsonp/?callback=?"; | |
| $.getJSON( url, { a: 1 }, function( data ) { | |
| ok( data, "data is returned from the server" ); | |
| equal( data.a, "1", "the value of data.a should be 1" ); | |
| done(); | |
| }); | |
| $.getJSON( url, { b: 2 }, function( data ) { | |
| ok( data, "data is returned from the server" ); | |
| equal( data.b, "2", "the value of data.b should be 2" ); | |
| done(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why not simply use stop(2) and replace done(); by start(); ?
the test will wait to have the 2 starts ready to execute tu run...