Skip to content

Commit b953fec

Browse files
committed
Ductyping galore, and do less work in all identify functions
1 parent 9de7beb commit b953fec

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

lib/index.js

+4-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*global HTMLDocument*/
21
function getAttributes(elm) {
32
var attrs = elm.attributes;
43
var result = {};
@@ -77,11 +76,7 @@ module.exports = {
7776
name: 'DOMNode',
7877
base: 'object',
7978
identify: function (obj) {
80-
if (!obj) {
81-
return false;
82-
}
83-
84-
return obj.nodeName && [2, 3, 4, 5, 6, 7, 9, 10, 11, 12].indexOf(obj.nodeType) > -1;
79+
return obj && obj.nodeName && [2, 3, 4, 5, 6, 7, 10, 11, 12].indexOf(obj.nodeType) > -1;
8580
},
8681
equal: function (a, b) {
8782
return a.nodeValue === b.nodeValue;
@@ -95,11 +90,7 @@ module.exports = {
9590
name: 'DOMComment',
9691
base: 'DOMNode',
9792
identify: function (obj) {
98-
if (!obj) {
99-
return false;
100-
}
101-
102-
return obj.nodeType === 8;
93+
return obj && obj.nodeType === 8;
10394
},
10495
equal: function (a, b) {
10596
return a.nodeValue === b.nodeValue;
@@ -113,28 +104,15 @@ module.exports = {
113104
name: 'HTMLDocument',
114105
base: 'DOMNode',
115106
identify: function (obj) {
116-
if ('HTMLDocument' in this) {
117-
return obj instanceof HTMLDocument;
118-
}
119-
120-
if (typeof window !== 'undefined') {
121-
return obj instanceof window.HTMLDocument;
122-
}
123-
124-
// Stupid duck typing case. Help :)
125-
return obj && obj.documentElement && obj.implementation;
107+
return obj && obj.nodeType === 9 && obj.documentElement && obj.implementation;
126108
}
127109
});
128110

129111
expect.addType({
130112
name: 'HTMLElement',
131113
base: 'DOMNode',
132114
identify: function (obj) {
133-
if (!obj) {
134-
return false;
135-
}
136-
137-
return !!(obj.nodeType === 1 && obj.nodeName && obj.attributes && obj.outerHTML);
115+
return obj && obj.nodeType === 1 && obj.nodeName && obj.attributes && obj.outerHTML;
138116
},
139117
equal: function (a, b) {
140118
return stringifyElement(a) === stringifyElement(b);

0 commit comments

Comments
 (0)