-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test in a real browser (err, I mean, Electron)
Inspired by #11
- Loading branch information
Showing
4 changed files
with
40 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
var isObject = require('is-object') | ||
var isWindow = require('is-window') | ||
const isObject = require(`is-object`) | ||
const isWindow = require(`is-window`) | ||
|
||
function isNode (val) { | ||
if (!isObject(val) || !isWindow(window) || typeof window.Node !== 'function') { | ||
return false | ||
} | ||
function isNode(val) { | ||
if (!isObject(val) || !isWindow(window) || typeof window.Node !== `function`) { | ||
return false | ||
} | ||
|
||
return typeof val.nodeType === 'number' && | ||
typeof val.nodeName === 'string' | ||
return typeof val.nodeType === `number` | ||
&& typeof val.nodeName === `string` | ||
} | ||
|
||
module.exports = isNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
'use strict' | ||
var JSDOM = require('jsdom').JSDOM | ||
var tape = require('tape') | ||
const test = require(`tape`) | ||
|
||
var isDom = require('./index') | ||
const isDom = require(`./index.js`) | ||
|
||
tape('is-dom', function (t) { | ||
var currentRealm = new JSDOM('<html><body></body></html>') | ||
var otherRealm = new JSDOM('<html><body></body></html>') | ||
global.window = currentRealm.window | ||
global.document = currentRealm.window.document | ||
test(`is-dom`, t => { | ||
t.plan(14) | ||
console.log(`wat`) | ||
t.equal(isDom(null), false) | ||
t.equal(isDom(null), false) | ||
t.equal(isDom(false), false) | ||
t.equal(isDom(new Date()), false) | ||
|
||
t.test('should check if supplied argument is a dom node', function (t) { | ||
t.plan(17) | ||
t.equal(isDom(null), false) | ||
t.equal(isDom(null), false) | ||
t.equal(isDom(false), false) | ||
t.equal(isDom(new Date()), false) | ||
t.equal(isDom(), false) | ||
t.equal(isDom([]), false) | ||
t.equal(isDom(2), false) | ||
t.equal(isDom('foo'), false) | ||
t.equal(isDom(/asda/), false) | ||
t.equal(isDom({}), false) | ||
t.equal(isDom(), false) | ||
t.equal(isDom([]), false) | ||
t.equal(isDom(2), false) | ||
t.equal(isDom(`foo`), false) | ||
t.equal(isDom(/asda/), false) | ||
t.equal(isDom({}), false) | ||
|
||
t.equal(isDom({ nodeType: 1, nodeName: 'BODY' }), true) | ||
t.equal(isDom(document.createElement('body')), true) | ||
t.equal(isDom(window), false) | ||
t.equal(isDom(document), true) | ||
|
||
t.equal(isDom(otherRealm.window), false) | ||
t.equal(isDom(otherRealm.window.document), true) | ||
t.equal(isDom(otherRealm.window.document.createElement('body')), true) | ||
}) | ||
t.equal(isDom({ nodeType: 1, nodeName: `BODY` }), true) | ||
t.equal(isDom(document.createElement(`body`)), true) | ||
t.equal(isDom(window), false) | ||
t.equal(isDom(document), true) | ||
}) |