1 QUnit
.module( "queue", { afterEach
: moduleTeardown
} );
5 if ( !includesModule( "queue" ) ) {
9 QUnit
.test( "queue() with other types", function( assert
) {
10 var done
= assert
.async( 2 );
14 var $div
= jQuery( {} ),
17 $div
.promise( "foo" ).done( function() {
18 assert
.equal( counter
, 0, "Deferred for collection with no queue is automatically resolved" );
22 .queue( "foo", function() {
23 assert
.equal( ++counter
, 1, "Dequeuing" );
24 jQuery
.dequeue( this, "foo" );
26 .queue( "foo", function() {
27 assert
.equal( ++counter
, 2, "Dequeuing" );
28 jQuery( this ).dequeue( "foo" );
30 .queue( "foo", function() {
31 assert
.equal( ++counter
, 3, "Dequeuing" );
33 .queue( "foo", function() {
34 assert
.equal( ++counter
, 4, "Dequeuing" );
37 $div
.promise( "foo" ).done( function() {
38 assert
.equal( counter
, 4, "Testing previous call to dequeue in deferred" );
42 assert
.equal( $div
.queue( "foo" ).length
, 4, "Testing queue length" );
44 assert
.equal( $div
.queue( "foo", undefined ).queue( "foo" ).length
, 4, ".queue('name',undefined) does nothing but is chainable (trac-5571)" );
46 $div
.dequeue( "foo" );
48 assert
.equal( counter
, 3, "Testing previous call to dequeue" );
49 assert
.equal( $div
.queue( "foo" ).length
, 1, "Testing queue length" );
51 $div
.dequeue( "foo" );
53 assert
.equal( counter
, 4, "Testing previous call to dequeue" );
54 assert
.equal( $div
.queue( "foo" ).length
, 0, "Testing queue length" );
56 $div
.dequeue( "foo" );
58 assert
.equal( counter
, 4, "Testing previous call to dequeue" );
59 assert
.equal( $div
.queue( "foo" ).length
, 0, "Testing queue length" );
63 QUnit
.test( "queue(name) passes in the next item in the queue as a parameter", function( assert
) {
66 var div
= jQuery( {} ),
69 div
.queue( "foo", function( next
) {
70 assert
.equal( ++counter
, 1, "Dequeueing" );
72 } ).queue( "foo", function( next
) {
73 assert
.equal( ++counter
, 2, "Next was called" );
75 } ).queue( "bar", function() {
76 assert
.equal( ++counter
, 3, "Other queues are not triggered by next()" );
82 QUnit
.test( "queue() passes in the next item in the queue as a parameter to fx queues", function( assert
) {
83 var done
= assert
.async();
86 var div
= jQuery( {} ),
89 div
.queue( function( next
) {
90 assert
.equal( ++counter
, 1, "Dequeueing" );
91 setTimeout( function() {
94 } ).queue( function( next
) {
95 assert
.equal( ++counter
, 2, "Next was called" );
97 } ).queue( "bar", function() {
98 assert
.equal( ++counter
, 3, "Other queues are not triggered by next()" );
101 jQuery
.when( div
.promise( "fx" ), div
).done( function() {
102 assert
.equal( counter
, 2, "Deferreds resolved" );
107 QUnit
.test( "callbacks keep their place in the queue", function( assert
) {
108 var done
= assert
.async();
110 var div
= jQuery( "<div>" ),
113 div
.queue( function( next
) {
114 assert
.equal( ++counter
, 1, "Queue/callback order: first called" );
115 setTimeout( next
, 200 );
116 } ).delay( 100 ).queue( function( next
) {
117 assert
.equal( ++counter
, 2, "Queue/callback order: second called" );
118 jQuery( this ).delay( 100 ).queue( function( next
) {
119 assert
.equal( ++counter
, 4, "Queue/callback order: fourth called" );
123 } ).queue( function( next
) {
124 assert
.equal( ++counter
, 3, "Queue/callback order: third called" );
128 div
.promise( "fx" ).done( function() {
129 assert
.equal( counter
, 4, "Deferreds resolved" );
134 QUnit
.test( "jQuery.queue should return array while manipulating the queue", function( assert
) {
137 var div
= document
.createElement( "div" );
139 assert
.ok( Array
.isArray( jQuery
.queue( div
, "fx", jQuery
.noop
) ), "jQuery.queue should return an array while manipulating the queue" );
142 QUnit
.test( "delay()", function( assert
) {
143 var done
= assert
.async();
146 var foo
= jQuery( {} ), run
= 0;
148 foo
.delay( 100 ).queue( function() {
150 assert
.ok( true, "The function was dequeued." );
154 assert
.equal( run
, 0, "The delay delayed the next function from running." );
157 QUnit
.test( "clearQueue(name) clears the queue", function( assert
) {
158 var done
= assert
.async( 2 );
161 var div
= jQuery( {} ),
164 div
.queue( "foo", function( next
) {
166 jQuery( this ).clearQueue( "foo" );
168 } ).queue( "foo", function() {
172 div
.promise( "foo" ).done( function() {
173 assert
.ok( true, "dequeue resolves the deferred" );
177 div
.dequeue( "foo" );
179 assert
.equal( counter
, 1, "the queue was cleared" );
183 QUnit
.test( "clearQueue() clears the fx queue", function( assert
) {
186 var div
= jQuery( {} ),
189 div
.queue( function( next
) {
192 setTimeout( function() {
193 jQuery( self
).clearQueue(); next();
195 } ).queue( function() {
199 assert
.equal( counter
, 1, "the queue was cleared" );
204 QUnit
.test( "fn.promise() - called when fx queue is empty", function( assert
) {
206 var foo
= jQuery( "#foo" ).clone().addBack(),
208 done
= assert
.async();
210 foo
.queue( function( next
) {
213 assert
.ok( !promised
, "Promised hasn't been called" );
214 setTimeout( next
, 10 );
216 foo
.promise().done( function() {
217 assert
.ok( promised
= true, "Promised" );
222 QUnit
.test( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", function( assert
) {
224 var done
= assert
.async();
225 var foo
= jQuery( "#foo" ),
227 foo
.promise( "queue" ).done( function() {
228 assert
.strictEqual( test
, undefined, "called immediately when queue was already empty" );
231 foo
.queue( "queue", function( next
) {
232 assert
.strictEqual( test
++, 1, "step one" );
233 setTimeout( next
, 0 );
234 } ).queue( "queue", function( next
) {
235 assert
.strictEqual( test
++, 2, "step two" );
236 setTimeout( function() {
238 assert
.strictEqual( test
++, 4, "step four" );
241 } ).promise( "queue" ).done( function() {
242 assert
.strictEqual( test
++, 3, "step three" );
245 foo
.dequeue( "queue" );
248 if ( includesModule( "effects" ) ) {
250 QUnit
.test( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", function( assert
) {
252 var done
= assert
.async();
253 var foo
= jQuery( "#foo" ),
261 complete: function() {
262 assert
.strictEqual( test
++, 1, "step one" );
264 } ).dequeue( "queue" );
266 foo
.promise( "queue" ).done( function() {
267 assert
.strictEqual( test
++, 2, "step two" );
274 QUnit
.test( ".promise(obj)", function( assert
) {
278 promise
= jQuery( "#foo" ).promise( "promise", obj
);
280 assert
.ok( typeof promise
.promise
=== "function", ".promise(type, obj) returns a promise" );
281 assert
.strictEqual( promise
, obj
, ".promise(type, obj) returns obj" );
284 QUnit
[ includesModule( "effects" ) ? "test" : "skip" ]( "delay() can be stopped", function( assert
) {
285 var done
= assert
.async();
289 .queue( "alternate", function( next
) {
291 assert
.ok( true, "This first function was dequeued" );
294 .delay( 1000, "alternate" )
295 .queue( "alternate", function() {
297 assert
.ok( true, "The function was dequeued immediately, the delay was stopped" );
299 .dequeue( "alternate" )
301 // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
302 .stop( "alternate", false, false )
307 storage
.default1
= true;
308 assert
.ok( false, "This queue should never run" );
311 // stop( clearQueue ) should clear the queue
312 .stop( true, false );
314 assert
.deepEqual( storage
, { alt1
: true, alt2
: true }, "Queue ran the proper functions" );
316 setTimeout( function() {
321 QUnit
[ includesModule( "effects" ) ? "test" : "skip" ]( "queue stop hooks", function( assert
) {
323 var done
= assert
.async();
324 var foo
= jQuery( "#foo" );
326 foo
.queue( function( next
, hooks
) {
327 hooks
.stop = function( gotoEnd
) {
328 assert
.equal( !!gotoEnd
, false, "Stopped without gotoEnd" );
333 foo
.queue( function( next
, hooks
) {
334 hooks
.stop = function( gotoEnd
) {
335 assert
.equal( gotoEnd
, true, "Stopped with gotoEnd" );
340 foo
.stop( false, true );