X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fmanipulation.js;h=ff3dff164ef6131153d37edd0f5c2f805170ffd5;hb=9523bb5ef02d4a106c7a6be540aa222a0d0bb01d;hp=6c3ecf8af800d4b7f0f44e21f3c108416d23335b;hpb=8b33e23ea07b206e96e39bb194675de80cff10ab;p=jquery.git
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 6c3ecf8..ff3dff1 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -1,4 +1,7 @@
-module("manipulation");
+module("manipulation", { teardown: moduleTeardown });
+
+// Ensure that an extended Array prototype doesn't break jQuery
+Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); };
var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); };
@@ -51,7 +54,7 @@ test("text(Function) with incoming value", function() {
});
var testWrap = function(val) {
- expect(18);
+ expect(19);
var defaultText = 'Try them out:'
var result = jQuery('#first').wrap(val( '
' )).text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
@@ -80,10 +83,20 @@ var testWrap = function(val) {
equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
// Try wrapping a disconnected node
+ var cacheLength = 0;
+ for (var i in jQuery.cache) {
+ cacheLength++;
+ }
+
j = jQuery("").wrap(val( "" ));
equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
+ for (i in jQuery.cache) {
+ cacheLength--;
+ }
+ equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
+
// Wrap an element containing a text node
j = jQuery("").wrap("
test
");
equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
@@ -102,12 +115,19 @@ var testWrap = function(val) {
// Wrap an element with a jQuery set and event
result = jQuery("").click(function(){
ok(true, "Event triggered.");
+
+ // Remove handlers on detached elements
+ result.unbind();
+ jQuery(this).unbind();
});
j = jQuery("").wrap(result);
equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
j.parent().trigger("click");
+
+ // clean up attached elements
+ QUnit.reset();
}
test("wrap(String|Element)", function() {
@@ -382,7 +402,8 @@ test("append(Function) with incoming value", function() {
});
test("append the same fragment with events (Bug #6997, 5566)", function () {
- expect(2 + (document.fireEvent ? 1 : 0));
+ var doExtra = !jQuery.support.noCloneEvent && document.fireEvent;
+ expect(2 + (doExtra ? 1 : 0));
stop(1000);
var element;
@@ -390,13 +411,17 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
// This patch modified the way that cloning occurs in IE; we need to make sure that
// native event handlers on the original object don't get disturbed when they are
// modified on the clone
- if (!jQuery.support.noCloneEvent && document.fireEvent) {
+ if ( doExtra ) {
element = jQuery("div:first").click(function () {
ok(true, "Event exists on original after being unbound on clone");
jQuery(this).unbind('click');
});
- element.clone(true).unbind('click')[0].fireEvent('onclick');
+ var clone = element.clone(true).unbind('click');
+ clone[0].fireEvent('onclick');
element[0].fireEvent('onclick');
+
+ // manually clean up detached elements
+ clone.remove();
}
element = jQuery("").click(function () {
@@ -714,7 +739,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
});
var testReplaceWith = function(val) {
- expect(20);
+ expect(21);
jQuery('#yahoo').replaceWith(val( 'buga' ));
ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
@@ -775,6 +800,9 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." );
+ var non_existant = jQuery('#does-not-exist').replaceWith( val("should not throw an error") );
+ equals( non_existant.length, 0, "Length of non existant element." );
+
var $div = jQuery("").appendTo("body");
// TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("