Add positive and negative testcases for isdomElement
This commit is contained in:
parent
d32db3c312
commit
97121dcf83
2 changed files with 16 additions and 2 deletions
3
index.js
3
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);
|
||||
};
|
||||
|
||||
|
|
|
|||
15
test.js
15
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue