diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2015-04-13 16:05:48 -0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2015-04-30 11:37:01 -0400 |
commit | 4cafb58ba43a85c1870b1ac6b233af262514997e (patch) | |
tree | e64551de5a4f1d9d7b282a8beddd209637f8211d /test/unit | |
parent | 1e7a2f3674d4bc62ba6cc537e42b2e417a9c5ba6 (diff) | |
download | jquery-4cafb58ba43a85c1870b1ac6b233af262514997e.tar.gz jquery-4cafb58ba43a85c1870b1ac6b233af262514997e.zip |
Manipulation: Detect sneaky no-content replaceWith input
Fixes gh-2204
Ref 642e9a45579cfa90861b8ea71a95dd077775caaf
Closes gh-1752
Closes gh-2206
(cherry picked from commit 4b27ae16a2b911f75b341b56d9d939bc65a9657a)
Conflicts:
src/manipulation.js
test/unit/manipulation.js
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/manipulation.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 8ce29b3a9..12ea6194b 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1329,15 +1329,20 @@ test( "replaceWith(string) for more than one element", function() { equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); }); -test( "Empty replaceWith (#13401; #13596)", 8, function() { - var $el = jQuery( "<div/>" ), +test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function() { + + expect( 25 ); + + var $el = jQuery( "<div/><div/>" ).html( "<p>0</p>" ), + expectedHTML = $el.html(), tests = { "empty string": "", "empty array": [], + "array of empty string": [ "" ], "empty collection": jQuery( "#nonexistent" ), - // in case of jQuery(...).replaceWith(); - "empty undefined": undefined + // in case of jQuery(...).replaceWith(); + "undefined": undefined }; jQuery.each( tests, function( label, input ) { @@ -1345,6 +1350,17 @@ test( "Empty replaceWith (#13401; #13596)", 8, function() { strictEqual( $el.html(), "", "replaceWith(" + label + ")" ); $el.html( "<b/>" ).children().replaceWith(function() { return input; }); strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" ); + $el.html( "<i/>" ).children().replaceWith(function( i ) { i; return input; }); + strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" ); + $el.html( "<p/>" ).children().replaceWith(function( i ) { + return i ? + input : + jQuery( this ).html( i + "" ); + }); + strictEqual( $el.eq( 0 ).html(), expectedHTML, + "replaceWith(function conditionally returning context)" ); + strictEqual( $el.eq( 1 ).html(), "", + "replaceWith(function conditionally returning " + label + ")" ); }); }); |