From: Jason Bedard Date: Sun, 19 Jul 2015 00:47:31 +0000 (-0700) Subject: Data: backport cleanData tests from gh-2480 X-Git-Tag: 1.12.0~157 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=624d6a8580a7e1108c81a6a777dc1be3d408bddf;p=jquery.git 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 --- diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 8db5ca924..c10534400 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2137,6 +2137,45 @@ test( "jQuery.cleanData", function() { } }); +test( "jQuery.cleanData eliminates all private data (gh-2127)", function() { + expect( 3 ); + + var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); + + jQuery._data( div[ 0 ], "gh-2127", "testing" ); + + ok( !jQuery.isEmptyObject( jQuery._data( div[ 0 ] ) ), "Ensure some private data exists" ); + + div.remove(); + + ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" ); + + ok( jQuery.isEmptyObject( jQuery._data( div[ 0 ] ) ), + "Private data is empty after node is removed" ); + + div.remove(); +}); + +test( "jQuery.cleanData eliminates all public data", function() { + expect( 2 ); + + var key, + div = jQuery( "
" ); + div.data( "some", "data" ); + ok( !jQuery.isEmptyObject( jQuery.data( div[ 0 ] ) ), "Ensure some public data exists" ); + + div.remove(); + + ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" ); + + // Make sure the expando is gone + for ( key in div[ 0 ] ) { + if ( /^jQuery/.test( key ) && jQuery[ key ] !== undefined ) { + ok( false, "Expando was not removed when there was no more data" ); + } + } +}); + test( "domManip plain-text caching (trac-6779)", function() { expect( 1 );