Refactor is.domElement to declare constants outside the function
This commit is contained in:
parent
b22d9e88db
commit
718a216797
2 changed files with 10 additions and 6 deletions
9
index.js
9
index.js
|
|
@ -161,11 +161,12 @@ is.inRange = (x, range) => {
|
|||
throw new TypeError(`Invalid range: ${util.inspect(range)}`);
|
||||
};
|
||||
|
||||
const NODE_TYPE_ELEMENT_NODE = 1;
|
||||
const DOM_PROPERTIES_TO_CHECK = ['innerHTML', 'ownerDocument', 'style', 'attributes', 'nodeValue'];
|
||||
|
||||
is.domElement = x => {
|
||||
const ELEMENT_NODE = 1;
|
||||
const propsToCheck = ['innerHTML', 'ownerDocument', 'style', 'attributes', 'nodeValue'];
|
||||
return is.object(x) && x.nodeType === ELEMENT_NODE && is.string(x.nodeName) &&
|
||||
!is.plainObject(x) && propsToCheck.every(prop => prop in x);
|
||||
return is.object(x) && x.nodeType === NODE_TYPE_ELEMENT_NODE && is.string(x.nodeName) &&
|
||||
!is.plainObject(x) && DOM_PROPERTIES_TO_CHECK.every(property => property in x);
|
||||
};
|
||||
|
||||
is.infinite = x => x === Infinity || x === -Infinity;
|
||||
|
|
|
|||
7
test.js
7
test.js
|
|
@ -9,6 +9,7 @@ const PromiseSubclassFixture = class extends Promise {};
|
|||
const ErrorSubclassFixture = class extends Error {};
|
||||
|
||||
const document = jsdom();
|
||||
const createDomElement = el => document.createElement(el);
|
||||
|
||||
const types = new Map([
|
||||
['undefined', undefined],
|
||||
|
|
@ -93,12 +94,14 @@ const types = new Map([
|
|||
new Object() // eslint-disable-line no-new-object
|
||||
]],
|
||||
['integer', 6],
|
||||
['domElement', ['div',
|
||||
['domElement', [
|
||||
'div',
|
||||
'input',
|
||||
'span',
|
||||
'img',
|
||||
'canvas',
|
||||
'script'].map(el => document.createElement(el))],
|
||||
'script'
|
||||
].map(createDomElement)],
|
||||
['non-domElements', [
|
||||
document.createTextNode('data'),
|
||||
document.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue