Skip to content

Commit

Permalink
Don't modify DOM elements when comparing them in deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohansen committed Dec 30, 2010
1 parent dc56062 commit 083b66a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/sinon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ var sinon = (function () {
var div = typeof document != "undefined" && document.createElement("div");

function isNode(obj) {
var success = false;

try {
div.appendChild(obj);
div.removeChild(obj);
obj.appendChild(div);
success = div.parentNode == obj;
} catch (e) {
return false;
} finally {
try {
obj.removeChild(div);
} catch (e) {}
}

return true;
return success;
}

function isElement(obj) {
Expand Down
9 changes: 9 additions & 0 deletions test/sinon_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@
assertFalse(sinon.deepEqual(this.element, el));
},

"should not modify DOM elements when comparing them": function () {
/*:DOC += <div id="hey"></div> */
var el = document.getElementById("hey");
sinon.deepEqual(el, {})

assertSame(document.body, el.parentNode);
assertEquals(0, el.childNodes.length);
},

"should pass deep objects": function () {
var func = function () {};

Expand Down

0 comments on commit 083b66a

Please sign in to comment.