Add check against a plain object

This commit is contained in:
Melvin Philips 2017-10-04 23:43:49 -07:00
parent 6a787261fe
commit 2e58d40c7d
2 changed files with 3 additions and 2 deletions

View file

@ -161,6 +161,6 @@ is.inRange = (x, range) => {
throw new TypeError(`Invalid range: ${util.inspect(range)}`);
};
is.domElement = x => is.object(x) && x.nodeType === 1;
is.domElement = x => is.object(x) && x.nodeType === 1 && is.string(x.nodeName) && !is.plainObject(x);
module.exports = is;

View file

@ -362,6 +362,7 @@ test('is.inRange', t => {
test('is.domElement', t => {
const document = jsdom();
t.true(m.domElement(document.createElement('div')));
t.false(m.domElement('hello world'));
t.false(m.domElement([]));
@ -371,5 +372,5 @@ test('is.domElement', t => {
t.false(m.domElement(0));
t.false(m.domElement(NaN));
t.false(m.domElement(Infinity));
t.false(m.domElement({}));
t.false(m.domElement({nodeType: 1, nodeName: 'div'}));
});