diff --git a/index.js b/index.js index c3e4634..4c3943d 100644 --- a/index.js +++ b/index.js @@ -162,8 +162,9 @@ is.inRange = (x, range) => { }; is.domElement = x => { + const ELEMENT_NODE = 1; const propsToCheck = ['innerHTML', 'ownerDocument', 'style', 'attributes', 'nodeValue']; - return is.object(x) && x.nodeType === 1 && is.string(x.nodeName) && + return is.object(x) && x.nodeType === ELEMENT_NODE && is.string(x.nodeName) && !is.plainObject(x) && propsToCheck.every(prop => prop in x); }; diff --git a/test.js b/test.js index 6ba0c79..3be5de6 100644 --- a/test.js +++ b/test.js @@ -93,7 +93,20 @@ const types = new Map([ new Object() // eslint-disable-line no-new-object ]], ['integer', 6], - ['domElement', document.createElement('div')] + ['domElement', ['div', + 'input', + 'span', + 'img', + 'canvas', + 'script'].map(el => document.createElement(el))], + ['non-domElements', [ + document.createTextNode('data'), + document.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'), + document.createComment('This is a comment'), + document, + document.implementation.createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'), + document.createDocumentFragment() + ]] ]); // This ensures a certain method matches only the types