Skip to content

Commit 624d6a8

Browse files
jbedardmgol
authored andcommitted
Data: backport cleanData tests from gh-2480
The tests needed a slight change as on compat we're not removing the value for expando but setting it to undefined. Refs gh-2480
1 parent b3eb2a1 commit 624d6a8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/unit/manipulation.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,45 @@ test( "jQuery.cleanData", function() {
21372137
}
21382138
});
21392139

2140+
test( "jQuery.cleanData eliminates all private data (gh-2127)", function() {
2141+
expect( 3 );
2142+
2143+
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
2144+
2145+
jQuery._data( div[ 0 ], "gh-2127", "testing" );
2146+
2147+
ok( !jQuery.isEmptyObject( jQuery._data( div[ 0 ] ) ), "Ensure some private data exists" );
2148+
2149+
div.remove();
2150+
2151+
ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" );
2152+
2153+
ok( jQuery.isEmptyObject( jQuery._data( div[ 0 ] ) ),
2154+
"Private data is empty after node is removed" );
2155+
2156+
div.remove();
2157+
});
2158+
2159+
test( "jQuery.cleanData eliminates all public data", function() {
2160+
expect( 2 );
2161+
2162+
var key,
2163+
div = jQuery( "<div/>" );
2164+
div.data( "some", "data" );
2165+
ok( !jQuery.isEmptyObject( jQuery.data( div[ 0 ] ) ), "Ensure some public data exists" );
2166+
2167+
div.remove();
2168+
2169+
ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" );
2170+
2171+
// Make sure the expando is gone
2172+
for ( key in div[ 0 ] ) {
2173+
if ( /^jQuery/.test( key ) && jQuery[ key ] !== undefined ) {
2174+
ok( false, "Expando was not removed when there was no more data" );
2175+
}
2176+
}
2177+
});
2178+
21402179
test( "domManip plain-text caching (trac-6779)", function() {
21412180

21422181
expect( 1 );

0 commit comments

Comments
 (0)