A follow-up to [6578] (which stopped adding expandos to elements that didn't have...
[jquery.git] / test / unit / data.js
index 5d390e1..8401fce 100644 (file)
@@ -1,20 +1,59 @@
 module("data");\r
 \r
+test("expando", function(){\r
+       expect(7);\r
+       \r
+       equals("expando" in jQuery, true, "jQuery is exposing the expando");\r
+       \r
+       var obj = {};\r
+       jQuery.data(obj);\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
+       jQuery.data(obj, true);\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
+       jQuery.data(obj, 'test');\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
+       jQuery.data(obj, "foo", "bar");\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
+       expect(6);\r
        var div = jQuery("#foo")[0];\r
        equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );\r
+       \r
        jQuery.data(div, "test", "success");\r
        equals( jQuery.data(div, "test"), "success", "Check for added data" );\r
+       \r
+       var data = jQuery.data(div);\r
+       same( data, { "test": "success" }, "Return complete data set" );\r
+       \r
        jQuery.data(div, "test", "overwritten");\r
        equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );\r
+       \r
        jQuery.data(div, "test", undefined);\r
        equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");\r
+       \r
        jQuery.data(div, "test", null);\r
        ok( jQuery.data(div, "test") === null, "Check for null data");\r
 });\r
 \r
 test(".data()", function() {\r
+       expect(1);\r
+\r
+       var div = jQuery("#foo");\r
+       div.data("test", "success");\r
+       isObj( div.data(), {test: "success"}, "data() get the entire data object" )\r
+})\r
+\r
+test(".data(String) and .data(String, Object)", function() {\r
        expect(22);\r
        var div = jQuery("#foo");\r
        equals( div.data("test"), undefined, "Check for no data exists" );\r
@@ -105,20 +144,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
@@ -154,9 +196,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
@@ -176,26 +215,8 @@ 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
-       expect(1);\r
-       \r
-       var div = jQuery({});\r
-       var counter = 0;\r
-       \r
-       div.queue("foo", function(next) {\r
-               counter++;\r
-               jQuery(this).clearQueue("foo");\r
-               next();\r
-       }).queue("foo", function(next) {\r
-               counter++;\r
-       });\r
-       \r
-       div.dequeue("foo");\r
-       \r
-       equals(counter, 1, "the queue was cleared");\r
 test("queue(name) passes in the next item in the queue as a parameter", function() {\r
        expect(2);\r
        \r
@@ -213,29 +234,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
-       }).queue(function() {\r
+               start();\r
+       }).queue("bar", function() {\r
                equals(++counter, 3, "Other queues are not triggered by next()")\r
        });\r
-       \r
-       div.dequeue();\r
-       \r
-       div.removeData();\r
+\r
 });\r
 \r
 test("clearQueue(name) clears the queue", function() {\r
@@ -265,13 +284,13 @@ test("clearQueue() clears the fx queue", function() {
        \r
        div.queue(function(next) {\r
                counter++;\r
-               jQuery(this).clearQueue();\r
-               next();\r
+               var self = this;\r
+               setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);\r
        }).queue(function(next) {\r
                counter++;\r
        });\r
        \r
-       div.dequeue();\r
-       \r
        equals(counter, 1, "the queue was cleared");\r
-})\r
+       \r
+       div.removeData();\r
+});\r