Skip to content

Commit 008e971

Browse files
committed
Add some more tests to make sure that pulling in data- properties on an element with no data set, works.
1 parent 97dfa0d commit 008e971

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/unit/data.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ test(".data(String) and .data(String, Object)", function() {
184184
});
185185

186186
test("data-* attributes", function() {
187-
expect(33);
187+
expect(37);
188188
var div = jQuery("<div>"),
189-
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
189+
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
190+
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
190191

191192
equals( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
192193

@@ -208,10 +209,11 @@ test("data-* attributes", function() {
208209
child.data("ignored", "cache");
209210
equals( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
210211

211-
var obj = child.data(), check = [ "myobj", "ignored", "other" ], num = 0;
212+
var obj = child.data(), obj2 = dummy.data(), check = [ "myobj", "ignored", "other" ], num = 0, num2 = 0;
212213

213214
for ( var i = 0, l = check.length; i < l; i++ ) {
214215
ok( obj[ check[i] ], "Make sure data- property exists when calling data-." );
216+
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
215217
}
216218

217219
for ( var prop in obj ) {
@@ -220,6 +222,12 @@ test("data-* attributes", function() {
220222

221223
equals( num, check.length, "Make sure that the right number of properties came through." );
222224

225+
for ( var prop in obj2 ) {
226+
num2++;
227+
}
228+
229+
equals( num2, check.length, "Make sure that the right number of properties came through." );
230+
223231
child.attr("data-other", "newvalue");
224232

225233
equals( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );

0 commit comments

Comments
 (0)