aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2008-02-03 18:43:04 +0000
committerJohn Resig <jeresig@gmail.com>2008-02-03 18:43:04 +0000
commitb0c7df65d0f92b77752e8f9b33898d0e3b2c05e8 (patch)
treec401a6b50fc00a18cac8ae25e293f212de2ca7bd /test
parent4a11e6d70b5c4b1473b62050929cffe3d2a67317 (diff)
downloadjquery-b0c7df65d0f92b77752e8f9b33898d0e3b2c05e8.tar.gz
jquery-b0c7df65d0f92b77752e8f9b33898d0e3b2c05e8.zip
You can now overwrite values returned from .data() with .bind("getData") - returning a value will override any bound value on that element.
Diffstat (limited to 'test')
-rw-r--r--test/unit/core.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/test/unit/core.js b/test/unit/core.js
index 3ca1e9510..3cb90aa78 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1398,7 +1398,7 @@ test("$.data", function() {
});
test(".data()", function() {
- expect(11);
+ expect(16);
var div = $("#foo");
ok( div.data("test") == undefined, "Check for no data exists" );
div.data("test", "success");
@@ -1406,25 +1406,41 @@ test(".data()", function() {
div.data("test", "overwritten");
ok( div.data("test") == "overwritten", "Check for overwritten data" );
- var hits = {test:0};
+ var hits = {test:0}, gets = {test:0};
div
.bind("setData",function(e,key,value){ hits[key] += value; })
.bind("setData.foo",function(e,key,value){ hits[key] += value; })
+ .bind("getData",function(e,key){ gets[key] += 1; })
+ .bind("getData.foo",function(e,key){ gets[key] += 3; });
div.data("test.foo", 2);
ok( div.data("test") == "overwritten", "Check for original data" );
ok( div.data("test.foo") == 2, "Check for namespaced data" );
ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" );
- ok( hits.test == 2, "Check triggered functions" );
+ equals( hits.test, 2, "Check triggered setter functions" );
+ equals( gets.test, 5, "Check triggered getter functions" );
hits.test = 0;
+ gets.test = 0;
div.data("test", 1);
ok( div.data("test") == 1, "Check for original data" );
ok( div.data("test.foo") == 2, "Check for namespaced data" );
ok( div.data("test.bar") == 1, "Check for unmatched namespace" );
- ok( hits.test == 1, "Check triggered functions" );
+ equals( hits.test, 1, "Check triggered setter functions" );
+ equals( gets.test, 5, "Check triggered getter functions" );
+
+ hits.test = 0;
+ gets.test = 0;
+
+ div
+ .bind("getData",function(e,key){ return key + "root"; })
+ .bind("getData.foo",function(e,key){ return key + "foo"; });
+
+ ok( div.data("test") == "testroot", "Check for original data" );
+ ok( div.data("test.foo") == "testfoo", "Check for namespaced data" );
+ ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" );
});
test("$.removeData", function() {