Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Brute force property removal when removeData([a,b,c]). Fixes #12786
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -621,6 +621,76 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert | |
}); | ||
}); | ||
|
||
test( "jQuery.fn.removeData supports interoperable removal of hyphenated properties via array (#12786)", function() { | ||
expect( 10 ); | ||
|
||
var div, plain, datas, keys; | ||
|
||
div = jQuery("<div/>", { id: "test12786" }).appendTo("#qunit-fixture"), | ||
datas = { | ||
"non-empty": "a string", | ||
"empty-string": "", | ||
"one-value": 1, | ||
"zero-value": 0, | ||
"an-array": [], | ||
"an-object": {}, | ||
"bool-true": true, | ||
"bool-false": false, | ||
// JSHint enforces double quotes, | ||
// but JSON strings need double quotes to parse | ||
// so we need escaped double quotes here | ||
"some-json": "{ \"foo\": \"bar\" }" | ||
}; | ||
|
||
keys = jQuery.map( datas, function( _, key ) { | ||
return key; | ||
}); | ||
|
||
// "keys" is an array that looks like this: | ||
// [ | ||
// "non-empty", "empty-string", "one-value", "zero-value", | ||
// "an-array", "an-object", "bool-true", "bool-false", "some-json" | ||
// ] | ||
|
||
div.data( datas ); | ||
deepEqual( div.data(), datas, "div.data() returns an object whose values match those of datas (div)" ); | ||
|
||
div.removeData( keys.hyphen ); | ||
ok( jQuery.isEmptyObject( div.data() ), "After removal by array of hyphenated keys, div.data() returns an object with no properties (div)" ); | ||
|
||
div.data( "a-a", 1 ); | ||
div.data( "b-b", 2 ); | ||
|
||
deepEqual( div.data( "a-a" ), 1, "div.data('a-a') returns value that matches the manually set value (div)" ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rwaldron
Author
Member
|
||
deepEqual( div.data( "b-b" ), 2, "div.data('b-b') returns value that matches the manually set value (div)" ); | ||
|
||
div.removeData([ "a-a", "b-b" ]); | ||
|
||
ok( jQuery.isEmptyObject( div.data() ), "After removal by array of hyphenated keys, div.data() returns an object with no properties (div)" ); | ||
|
||
plain = jQuery({}); | ||
|
||
plain.data( datas ); | ||
deepEqual( plain.data(), datas, "plain.data() returns an object whose values match those of datas (plain)" ); | ||
|
||
plain.removeData( keys ); | ||
|
||
ok( jQuery.isEmptyObject( plain.data() ), "After removal by array of hyphenated keys, plain.data() returns an object with no properties (plain)" ); | ||
|
||
|
||
plain = jQuery({}); | ||
|
||
plain.data( "a-a", 1 ); | ||
plain.data( "b-b", 2 ); | ||
|
||
deepEqual( plain.data( "a-a" ), 1, "plain.data('a-a') returns value that matches the manually set value (plain)" ); | ||
deepEqual( plain.data( "b-b" ), 2, "plain.data('b-b') returns value that matches the manually set value (plain)" ); | ||
|
||
plain.removeData([ "a-a", "b-b" ]); | ||
|
||
ok( jQuery.isEmptyObject( plain.data() ), "After removal by array of hyphenated keys, plain.data() returns an object with no properties (plain)" ); | ||
}); | ||
|
||
// Test originally by Moschel | ||
test("Triggering the removeData should not throw exceptions. (#10080)", function() { | ||
expect(1); | ||
|
Very deep ;-)