add better support of DOM nodes into equality matcher
This commit is contained in:
@@ -116,6 +116,31 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
a.ignoreCase == b.ignoreCase;
|
||||
}
|
||||
if (typeof a != 'object' || typeof b != 'object') { return false; }
|
||||
// we don't need to compare DOM nodes in node.js
|
||||
var globalObject = typeof window == 'undefined' ? global : window;
|
||||
if (globalObject.Node && globalObject.HTMLElement) {
|
||||
var aIsDomNode = a instanceof Node;
|
||||
var bIsDomNode = b instanceof Node;
|
||||
if (aIsDomNode && bIsDomNode) {
|
||||
// At first try to use DOM3 method isEqualNode
|
||||
if (a.isEqualNode) {
|
||||
return a.isEqualNode(b);
|
||||
}
|
||||
// IE8 doesn't support isEqualNode, try to use outerHTML && innerText
|
||||
var aIsElement = a instanceof HTMLElement;
|
||||
var bIsElement = b instanceof HTMLElement;
|
||||
if (aIsElement && bIsElement) {
|
||||
return a.outerHTML == b.outerHTML;
|
||||
}
|
||||
if (aIsElement || bIsElement) {
|
||||
return false;
|
||||
}
|
||||
return a.innerText == b.innerText && a.textContent == b.textContent;
|
||||
}
|
||||
if (aIsDomNode || bIsDomNode) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||
var length = aStack.length;
|
||||
|
||||
Reference in New Issue
Block a user