diff --git a/tests/jquery.testHelper.js b/tests/jquery.testHelper.js index 5bd1c0d9..384d7efb 100644 --- a/tests/jquery.testHelper.js +++ b/tests/jquery.testHelper.js @@ -75,6 +75,8 @@ }); }, + // TODO move to eventSequence and invoke pageSequence with default of + // changepage event pageSequence: function(fns, event){ var fn = fns.shift(), self = this; @@ -94,6 +96,7 @@ clearTimeout(warnTimer); // Let the current stack unwind before we fire off the next item in the sequence. + // TODO setTimeout(self.pageSequence, 0, [fns, event]); setTimeout(function(){ self.pageSequence(fns, event); }, 0); }); diff --git a/tests/unit/event/event_core.js b/tests/unit/event/event_core.js index cf31e4bb..9958023b 100644 --- a/tests/unit/event/event_core.js +++ b/tests/unit/event/event_core.js @@ -28,6 +28,8 @@ Math.abs = absFn; $.Event.prototype.originalEvent = originalEventFn; $.Event.prototype.preventDefault = preventDefaultFn; + + $(window).unbind( "throttledresize" ); } }); @@ -69,8 +71,6 @@ $('#qunit-fixture').touchstart(); stop(); }); - - test( "defining event functions sets the attrFn to true", function(){ $.each(events, function(i, name){ @@ -380,68 +380,68 @@ returnValue: undefined //NOTE result of unbind function call }); }); - + /* The following 4 tests are async so that the throttled event triggers don't interfere with subsequent tests */ - + asyncTest( "throttledresize event proxies resize events", function(){ var called = false; $(window).bind( "throttledresize", function(){ called = true; }); - $(window).trigger("resize"); - - setTimeout(function(){ - ok( called ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); + $.testHelper.sequence([ + function(){ $(window).trigger( "resize" ); }, + function(){ ok( called ); }, + function(){ + start(); + } + ], 200); }); asyncTest( "throttledresize event prevents resize events from firing more frequently than 250ms", function(){ var called = 0; + $(window).bind( "throttledresize", function(){ - called ++; + called++; }); - $(window).trigger( "resize" ).trigger( "resize" ); - - setTimeout(function(){ - ok( called == 1 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 100); + // NOTE 250 ms * 3 = 750ms which is plenty of time + // for the events to trigger before the next test, but + // not so much time that the second resize will be triggered + // before the call to same() is made + $.testHelper.sequence([ + function(){ + $(window).trigger( "resize" ).trigger( "resize" ); + }, + + // verify that only one throttled resize was called after 250ms + function(){ same( called, 1 ); }, + + function(){ + start(); + } + ], 250); }); - - asyncTest( "throttledresize event promises that a held call will execute after trottled timeout", function(){ - var called = 0; - + + asyncTest( "throttledresize event promises that a held call will execute only once after throttled timeout", function(){ + var called = 0; + $(window).bind( "throttledresize", function(){ - called ++; + called++; }); - $(window).trigger( "resize" ).trigger( "resize" ); - setTimeout(function(){ - ok( called == 2 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); - }); - - asyncTest( "throttledresize event promises that a held call will execute only once after trottled timeout", function(){ - var called = 0; - - $(window).bind( "throttledresize", function(){ - called ++; - }); + $.testHelper.sequence([ + // trigger a ton of throttledresize events + function(){ + $(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" ); + }, - $(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" ); - - setTimeout(function(){ - ok( called == 2 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); + // verify that after enough time has gone by to accomodate all of them + // ie 750ms, only to calls to the bound function were made + function(){ + same( called, 2 ); + start(); + } + ], 750); }); - })(jQuery); diff --git a/tests/unit/event/index.html b/tests/unit/event/index.html index 29568c0e..f582a6c1 100644 --- a/tests/unit/event/index.html +++ b/tests/unit/event/index.html @@ -6,6 +6,7 @@