On Oct 22, 2009, at Oct 22,6:53 PM , gMinuses wrote:
> Is there a thorough explanation or tutorial to introduce how > it actually works? I just looked at the code. The key is that the bodies of your tests don't actually run when the test() function executes. They are queued up as tasks and then run via a loop which is scheduled by a call to setTimeout within qunit. Without going into the gory details, qunit assumes your test is complete unless told otherwise. stop() tells qunit to stop itself until told otherwise. So even when your test body finishes, qunit doesn't assume the test is over and go on to the next one. Presumably you have something that will execute a callback asynchronously, possibly runnings ok()s. When your test is done, failed or not, you call start() to tell qunit to finish up your test (check expects, etc.) and go on to subsequent tests. There's also an option for stop, stop(n), which tells qunit to come back to life after n milliseconds if it hasn't been told to earlier via start(). You can use this to handle cases where, because of a failure in the test, start() never gets called which would otherwise cause the test suite to stop midway. > asyncTest('yet another asyncTest', function() { > setTimeout(function() { > console.log(5); > ok(true, 'yet another success'); > start(); > > stop() > $.ajax({ > url: './index.html', > success: function() { > console.log(6); > ok(true, 'yet another ajax success'); > start(); > } > }) > > }, 100) > }) qunit doesn't expect to be started and stopped more than once per test. There's really no value to that. start and stop are starting and stopping quint, not your test. Your code executes as if start() and stop() weren't there: they're just signals to qunit. It makes no sense to signal qunit to start and then in the next line tell it not to start. You should execute stop() once per async test and start() once per async test. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---