jquery data: closes #5224. Exposing the expando.
[jquery.git] / test / unit / data.js
index 14483a1..46e46ed 100644 (file)
@@ -1,5 +1,21 @@
 module("data");\r
 \r
+test("expando", function(){\r
+       expect(4);\r
+       \r
+       equals("expando" in jQuery, true, "jQuery is exposing the expando");\r
+       \r
+       var obj = {};\r
+       jQuery.data(obj, "foo", "bar");\r
+\r
+       equals(jQuery.expando in obj, true, "jQuery.data added an expando to the object");      \r
+       \r
+       var id = obj[jQuery.expando];\r
+       equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache");\r
+       \r
+       equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly");\r
+});\r
+\r
 test("jQuery.data", function() {\r
        expect(5);\r
        var div = jQuery("#foo")[0];\r
@@ -113,20 +129,23 @@ test(".removeData()", function() {
 });\r
 \r
 test("queue() defaults to 'fx' type", function () {\r
-       expect(2);\r
+       expect(1);\r
        stop();\r
 \r
+       var counter = 0;\r
+\r
        var $foo = jQuery("#foo");\r
-       $foo.queue("fx", [ "sample", "array" ]);\r
-       var arr = $foo.queue();\r
-       isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");\r
-       $foo.queue([ "another", "one" ]);\r
-       var arr = $foo.queue("fx");\r
-       isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");\r
-       // clean up after test\r
-       $foo.queue([]);\r
 \r
-       start();\r
+       $foo.queue(function() {\r
+               var self = this;\r
+               setTimeout(function() {\r
+                       jQuery(self).dequeue("fx");\r
+                       start();\r
+               }, 200);\r
+       }).queue(function() {\r
+               ok( "dequeuing 'fx' calls queues created with no name" )\r
+       });\r
+\r
 });\r
 \r
 test("queue() with other types",function() {\r
@@ -162,9 +181,6 @@ test("queue() with other types",function() {
        \r
        equals( counter, 4, "Testing previous call to dequeue" );\r
        equals( $div.queue('foo').length, 0, "Testing queue length" );\r
-       \r
-       // Clean up\r
-       $div.removeData();\r
 });\r
 \r
 test("queue(name) passes in the next item in the queue as a parameter", function() {\r
@@ -184,8 +200,6 @@ test("queue(name) passes in the next item in the queue as a parameter", function
        });\r
        \r
        div.dequeue("foo");\r
-       \r
-       div.removeData();\r
 });\r
 \r
 test("queue(name) passes in the next item in the queue as a parameter", function() {\r
@@ -205,27 +219,27 @@ test("queue(name) passes in the next item in the queue as a parameter", function
        });\r
        \r
        div.dequeue("foo");\r
-       \r
-       div.removeData();\r
 });\r
 \r
 test("queue() passes in the next item in the queue as a parameter to fx queues", function() {\r
        expect(2);\r
+       stop();\r
        \r
        var div = jQuery({});\r
        var counter = 0;\r
        \r
        div.queue(function(next) {\r
                equals(++counter, 1, "Dequeueing");\r
-               next();\r
+               var self = this;\r
+               setTimeout(function() { next() }, 500);\r
        }).queue(function(next) {\r
                equals(++counter, 2, "Next was called");\r
                next();\r
+               start();\r
        }).queue("bar", function() {\r
                equals(++counter, 3, "Other queues are not triggered by next()")\r
        });\r
-       \r
-       div.removeData();\r
+\r
 });\r
 \r
 test("clearQueue(name) clears the queue", function() {\r
@@ -245,8 +259,6 @@ test("clearQueue(name) clears the queue", function() {
        div.dequeue("foo");\r
        \r
        equals(counter, 1, "the queue was cleared");\r
-       \r
-       div.removeData();\r
 });\r
 \r
 test("clearQueue() clears the fx queue", function() {\r
@@ -257,7 +269,8 @@ test("clearQueue() clears the fx queue", function() {
        \r
        div.queue(function(next) {\r
                counter++;\r
-               setTimeout(function() { jQuery(this).clearQueue(); next(); }, 50);\r
+               var self = this;\r
+               setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);\r
        }).queue(function(next) {\r
                counter++;\r
        });\r