aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-04-11 13:40:14 +0200
committerjaubourg <j@ubourg.net>2011-04-11 13:40:14 +0200
commit3411d47a6a952e283864d2401438a6764d925b74 (patch)
tree7d8857e732e565703d55a7e3941b60c0ee7c9255 /test
parentf182b7b92117f8e353a1f712569d3d2642100862 (diff)
downloadjquery-3411d47a6a952e283864d2401438a6764d925b74.tar.gz
jquery-3411d47a6a952e283864d2401438a6764d925b74.zip
Adds _mark and _unmark as a mean to keep track of ongoing non-queued animations in fn.promise.
Diffstat (limited to 'test')
-rw-r--r--test/unit/queue.js111
1 files changed, 106 insertions, 5 deletions
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 31e587db2..05461cd26 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,10 +1,17 @@
module("queue", { teardown: moduleTeardown });
test("queue() with other types",function() {
- expect(9);
+ expect(11);
var counter = 0;
- var $div = jQuery({});
+ stop();
+
+ var $div = jQuery({}),
+ defer;
+
+ $div.promise('foo').done(function() {
+ equals( counter, 0, "Deferred for collection with no queue is automatically resolved" );
+ });
$div
.queue('foo',function(){
@@ -22,6 +29,11 @@ test("queue() with other types",function() {
equals( ++counter, 4, "Dequeuing" );
});
+ defer = $div.promise('foo').done(function() {
+ equals( counter, 4, "Testing previous call to dequeue in deferred" );
+ start();
+ });
+
equals( $div.queue('foo').length, 4, "Testing queue length" );
$div.dequeue('foo');
@@ -74,7 +86,7 @@ test("queue(name) passes in the next item in the queue as a parameter", function
});
test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
- expect(2);
+ expect(3);
stop();
var div = jQuery({});
@@ -87,11 +99,15 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
}).queue(function(next) {
equals(++counter, 2, "Next was called");
next();
- start();
}).queue("bar", function() {
equals(++counter, 3, "Other queues are not triggered by next()")
});
+ jQuery.when( div.promise("fx"), div ).done(function() {
+ equals(counter, 2, "Deferreds resolved");
+ start();
+ });
+
});
test("delay()", function() {
@@ -110,7 +126,9 @@ test("delay()", function() {
});
test("clearQueue(name) clears the queue", function() {
- expect(1);
+ expect(2);
+
+ stop()
var div = jQuery({});
var counter = 0;
@@ -123,6 +141,11 @@ test("clearQueue(name) clears the queue", function() {
counter++;
});
+ div.promise("foo").done(function() {
+ ok( true, "dequeue resolves the deferred" );
+ start();
+ });
+
div.dequeue("foo");
equals(counter, 1, "the queue was cleared");
@@ -146,3 +169,81 @@ test("clearQueue() clears the fx queue", function() {
div.removeData();
});
+
+test("_mark() and _unmark()", function() {
+ expect(1);
+
+ var div = {},
+ $div = jQuery( div );
+
+ stop();
+
+ jQuery._mark( div, "foo" );
+ jQuery._mark( div, "foo" );
+ jQuery._unmark( div, "foo" );
+ jQuery._unmark( div, "foo" );
+
+ $div.promise( "foo" ).done(function() {
+ ok( true, "No more marks" );
+ start();
+ });
+});
+
+test("_mark() and _unmark() default to 'fx'", function() {
+ expect(1);
+
+ var div = {},
+ $div = jQuery( div );
+
+ stop();
+
+ jQuery._mark( div );
+ jQuery._mark( div );
+ jQuery._unmark( div, "fx" );
+ jQuery._unmark( div );
+
+ $div.promise().done(function() {
+ ok( true, "No more marks" );
+ start();
+ });
+});
+
+test("promise()", function() {
+ expect(1);
+
+ stop();
+
+ var objects = [];
+
+ jQuery.each( [{}, {}], function( i, div ) {
+ var $div = jQuery( div );
+ $div.queue(function( next ) {
+ setTimeout( function() {
+ if ( i ) {
+ next();
+ setTimeout( function() {
+ jQuery._unmark( div );
+ }, 20 );
+ } else {
+ jQuery._unmark( div );
+ setTimeout( function() {
+ next();
+ }, 20 );
+ }
+ }, 50 );
+ }).queue(function( next ) {
+ next();
+ });
+ jQuery._mark( div );
+ objects.push( $div );
+ });
+
+ jQuery.when.apply( jQuery, objects ).done(function() {
+ ok( true, "Deferred resolved" );
+ start();
+ });
+
+ jQuery.each( objects, function() {
+ this.dequeue();
+ });
+});