Refactor is.domElement to declare constants outside the function

This commit is contained in:
Melvin Philips 2017-10-05 14:17:39 -07:00
parent b22d9e88db
commit 718a216797
2 changed files with 10 additions and 6 deletions

View file

@ -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;

View file

@ -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"'),