Thank you! This really does the trick, but now the real problem is to
using a setInterval to check location.hash to implement an
"onhashchange" event. These events are all asynchronous, and I can't
get my tests passed, here is the test case:

http://dl.getdropbox.com/u/1402827/hashchange/index.html

I didn't make any ajax call.

On Oct 24, 5:04 am, Ricardo Tomasi <ricardob...@gmail.com> wrote:
> Just use sync: true in all tests and put an end to this discussion :)
>
> On Oct 22, 9:26 pm, gMinuses <gminu...@gmail.com> wrote:
>
> > I'd like to test the following code to make sure:
>
> > 1. setTimeout calls the function
> > 2. ajax success callback is called
>
> > setTimeout(function() {
>
> >         $.ajax({
> >                 url: './index.html',
> >                 success: function() {}
> >         })
>
> > }, 100);
>
> > If I only have one nested asynchronous test like this, it works:
>
> > asyncTest('asyncTest', function() {
> >         setTimeout(function() {
> >                 console.log(1);
> >                 ok(true, 'success');
> >                 start();
>
> >                 asyncTest('nested asyncTest', function() {
> >                         $.ajax({
> >                                 url: './index.html',
> >                                 success: function() {
> >                                         console.log(2);
> >                                         ok(true, 'ajax success');
> >                                         start();
> >                                 }
> >                         })
> >                 })
>
> >         }, 100)
>
> > })
>
> > But if there are multiple tests, it works, but run out of order:
>
> > asyncTest('asyncTest', function() {
> >         setTimeout(function() {
> >                 console.log(1);
> >                 ok(true, 'success');
> >                 start();
>
> >                 asyncTest('nested asyncTest', function() {
> >                         $.ajax({
> >                                 url: './index.html',
> >                                 success: function() {
> >                                         console.log(2);
> >                                         ok(true, 'ajax success');
> >                                         start();
> >                                 }
> >                         })
> >                 })
>
> >         }, 100)
>
> > })
>
> > asyncTest('another asyncTest', function() {
> >         setTimeout(function() {
> >                 console.log(3);
> >                 ok(true, 'another success');
> >                 start();
>
> >                 asyncTest('another nested asyncTest', function() {
> >                         $.ajax({
> >                                 url: './index.html',
> >                                 success: function() {
> >                                         console.log(4);
> >                                         ok(true, 'another ajax success');
> >                                         start();
> >                                 }
> >                         })
> >                 })
>
> >         }, 100)
>
> > })
>
> > If you open firebug, you can see the order is "1,3,2,4", which can
> > cause disasters.
>
> > The real world problem is that I use setInterval to periodically check
> > location.hash to implement a cross-browser "onhashchange" event, and I
> > bind a function to this event, when the function gets called, it will
> > make an ajax call. I set a different value to location.hash in every
> > test to trigger the event, which is actually asynchronous. So how do I
> > use qunit to test this code?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to