Thanks! It's really nice to have an example to learn from. In fact,
I've visited jQuery BBQ before I made this post. I didn't aware the
unit tests, but have read the source code.  I found the code a little
bit hard to read: variable names are very special, and modules are
strongly coupled. What I really want what is just a simple cross-
browser "onhashchange" event implementation, but I was unable to
extract that from BBQ easily, so I finally decide to implement my own
version, and stuck with unit tests.

I'll try to understand the code for more times, and come up with a
standalone "onhashchange" event implementation.

Thanks again!

On Oct 24, 9:12 pm, "\"Cowboy\" Ben Alman" <cow...@rj3.net> wrote:
> jQuery BBQ provides window.onhashchange 
> ->http://benalman.com/projects/jquery-bbq-plugin/
>
> And in the unit tests, many of which are asynchronous, a queue of
> callbacks is used to execute them in order. See the "run_many_tests"
> function in the jQuery BBQ unit tests page to see how I implemented
> it.
>
> - Ben
>
> On Oct 23, 8:29 pm, gMinuses <gminu...@gmail.com> wrote:
>
> > 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