1 module( "queue", { teardown: moduleTeardown });
3 test( "queue() with other types", 14, function() {
9 $div.promise( "foo" ).done(function() {
10 equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
14 .queue("foo",function(){
15 equal( ++counter, 1, "Dequeuing" );
16 jQuery.dequeue(this,"foo");
18 .queue("foo",function(){
19 equal( ++counter, 2, "Dequeuing" );
20 jQuery(this).dequeue("foo");
22 .queue("foo",function(){
23 equal( ++counter, 3, "Dequeuing" );
25 .queue("foo",function(){
26 equal( ++counter, 4, "Dequeuing" );
29 $div.promise("foo").done(function() {
30 equal( counter, 4, "Testing previous call to dequeue in deferred" );
34 equal( $div.queue("foo").length, 4, "Testing queue length" );
36 equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
40 equal( counter, 3, "Testing previous call to dequeue" );
41 equal( $div.queue("foo").length, 1, "Testing queue length" );
45 equal( counter, 4, "Testing previous call to dequeue" );
46 equal( $div.queue("foo").length, 0, "Testing queue length" );
50 equal( counter, 4, "Testing previous call to dequeue" );
51 equal( $div.queue("foo").length, 0, "Testing queue length" );
55 test("queue(name) passes in the next item in the queue as a parameter", function() {
61 div.queue("foo", function(next) {
62 equal(++counter, 1, "Dequeueing");
64 }).queue("foo", function(next) {
65 equal(++counter, 2, "Next was called");
67 }).queue("bar", function() {
68 equal(++counter, 3, "Other queues are not triggered by next()");
74 test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
81 div.queue(function(next) {
82 equal(++counter, 1, "Dequeueing");
83 setTimeout(function() { next(); }, 500);
84 }).queue(function(next) {
85 equal(++counter, 2, "Next was called");
87 }).queue("bar", function() {
88 equal(++counter, 3, "Other queues are not triggered by next()");
91 jQuery.when( div.promise("fx"), div ).done(function() {
92 equal(counter, 2, "Deferreds resolved");
97 test("callbacks keep their place in the queue", function() {
100 var div = jQuery("<div>"),
103 div.queue(function( next ) {
104 equal( ++counter, 1, "Queue/callback order: first called" );
105 setTimeout( next, 200 );
106 }).delay( 100 ).queue(function( next ) {
107 equal( ++counter, 2, "Queue/callback order: second called" );
108 jQuery( this ).delay( 100 ).queue(function( next ) {
109 equal( ++counter, 4, "Queue/callback order: fourth called" );
113 }).queue(function( next ) {
114 equal( ++counter, 3, "Queue/callback order: third called" );
118 div.promise("fx").done(function() {
119 equal(counter, 4, "Deferreds resolved");
124 test( "jQuery.queue should return array while manipulating the queue", 1, function() {
125 var div = document.createElement("div");
127 ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" );
130 test("delay()", function() {
134 var foo = jQuery({}), run = 0;
136 foo.delay(100).queue(function(){
138 ok( true, "The function was dequeued." );
142 equal( run, 0, "The delay delayed the next function from running." );
145 test("clearQueue(name) clears the queue", function() {
150 var div = jQuery({}),
153 div.queue("foo", function( next ) {
155 jQuery(this).clearQueue("foo");
157 }).queue("foo", function() {
161 div.promise("foo").done(function() {
162 ok( true, "dequeue resolves the deferred" );
168 equal(counter, 1, "the queue was cleared");
171 test("clearQueue() clears the fx queue", function() {
174 var div = jQuery({}),
177 div.queue(function( next ) {
180 setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
181 }).queue(function() {
185 equal(counter, 1, "the queue was cleared");
190 asyncTest( "fn.promise() - called when fx queue is empty", 3, function() {
191 var foo = jQuery( "#foo" ).clone().addBack(),
194 foo.queue( function( next ) {
196 ok( !promised, "Promised hasn't been called" );
197 setTimeout( next, 10 );
199 foo.promise().done( function() {
200 ok( promised = true, "Promised" );
205 asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function() {
206 var foo = jQuery( "#foo" ),
208 foo.promise( "queue" ).done( function() {
209 strictEqual( test, undefined, "called immediately when queue was already empty" );
212 foo.queue( "queue", function( next ) {
213 strictEqual( test++, 1, "step one" );
214 setTimeout( next, 0 );
215 }).queue( "queue", function( next ) {
216 strictEqual( test++, 2, "step two" );
217 setTimeout( function() {
219 strictEqual( test++, 4, "step four" );
222 }).promise( "queue" ).done( function() {
223 strictEqual( test++, 3, "step three" );
226 foo.dequeue( "queue" );
229 asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() {
230 var foo = jQuery( "#foo" ),
238 complete: function() {
239 strictEqual( test++, 1, "step one" );
241 }).dequeue( "queue" );
243 foo.promise( "queue" ).done( function() {
244 strictEqual( test++, 2, "step two" );
250 test( ".promise(obj)", function() {
254 promise = jQuery( "#foo" ).promise( "promise", obj );
256 ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
257 strictEqual( promise, obj, ".promise(type, obj) returns obj" );
261 if ( jQuery.fn.stop ) {
262 test("delay() can be stopped", function() {
268 .queue( "alternate", function( next ) {
270 ok( true, "This first function was dequeued" );
273 .delay( 1000, "alternate" )
274 .queue( "alternate", function() {
276 ok( true, "The function was dequeued immediately, the delay was stopped" );
278 .dequeue( "alternate" )
280 // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
281 .stop( "alternate", false, false )
286 done.default1 = true;
287 ok( false, "This queue should never run" );
290 // stop( clearQueue ) should clear the queue
291 .stop( true, false );
293 deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
295 setTimeout(function() {
300 asyncTest( "queue stop hooks", 2, function() {
301 var foo = jQuery( "#foo" );
303 foo.queue( function( next, hooks ) {
304 hooks.stop = function( gotoEnd ) {
305 equal( !!gotoEnd, false, "Stopped without gotoEnd" );
310 foo.queue( function( next, hooks ) {
311 hooks.stop = function( gotoEnd ) {
312 equal( gotoEnd, true, "Stopped with gotoEnd" );
317 foo.stop( false, true );
320 } // if ( jQuery.fn.stop )