aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPaul Ramos <paul.b.ramos@gmail.com>2012-12-10 16:12:54 -0500
committerDave Methvin <dave.methvin@gmail.com>2012-12-11 23:35:22 -0500
commitf12611feb43adb2b014eb2183db0713451746aff (patch)
treef860ba7ae1a785f024c0a4fb670e7f8be5c127bb /test
parentaad235b3251494afe71fd5bb6031e11965af9bdb (diff)
downloadjquery-f12611feb43adb2b014eb2183db0713451746aff.tar.gz
jquery-f12611feb43adb2b014eb2183db0713451746aff.zip
Fix #4087. insertAfter, insertBefore, etc do not work if origin and destination are same element. Close gh-1068.
Diffstat (limited to 'test')
-rw-r--r--test/unit/manipulation.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 9d8c93321..41db7291d 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -2274,3 +2274,37 @@ test( "wrapping scripts (#10470)", function() {
strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
jQuery( script ).remove();
});
+
+test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function() {
+
+ expect( 10 );
+
+ var elems;
+
+ jQuery.each([
+ "appendTo",
+ "prependTo",
+ "insertBefore",
+ "insertAfter",
+ "replaceAll"
+ ], function( index, name ) {
+ elems = jQuery( [
+ "<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>",
+ "<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>",
+ "<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>"
+ ] ).appendTo( "#qunit-fixture" );
+
+ // complex case based on http://jsfiddle.net/pbramos/gZ7vB/
+ jQuery("#test4087-complex div")[ name ]("#test4087-complex li:last-child div:last-child");
+ equal( jQuery("#test4087-complex li:last-child div").length, name === "replaceAll" ? 1 : 2, name +" a node to itself, complex case." );
+
+ // simple case
+ jQuery( ".test4087-1" )[ name ](".test4087-1");
+ equal( jQuery(".test4087-1").length, 1, name +" a node to itself, simple case." );
+
+ // clean for next test
+ jQuery("#test4087-complex").remove();
+ jQuery("#test4087-simple").remove();
+ jQuery("#test4087-multiple").remove();
+ });
+});