Files
lodash/test/isElement.test.js
Benjamin Tan d5ef31929a Add initial test files from lodash v4. (#4172)
* Install test dependencies.

* Add initial test files.

These files were created using a simplistic AST manipulator using `recast` to
preserve formatting. There's bound to be a huge chunk of errors, but this serves
as a good start. QUnit was replaced with Mocha, with ES2015 imports running via
`esm`.

As far as possible, QUnit-specific syntax has been replaced with Mocha's
`describe` and `it`, while the native Node.js `assert` module is used for
assertions. Files in the `test` directory ending in `.test.js` will be treated
as test files.

* Add initial passing files to test run.
2019-02-12 09:11:32 -08:00

59 lines
2.0 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { document, body, falsey, stubFalse, args, slice, symbol, realm } from './utils.js';
import isElement from '../isElement.js';
describe('isElement', function() {
it('should return `true` for elements', function() {
if (document) {
assert.strictEqual(isElement(body), true);
}
});
it('should return `true` for non-plain objects', function() {
function Foo() {
this.nodeType = 1;
}
assert.strictEqual(isElement(new Foo), true);
});
it('should return `false` for non DOM elements', function() {
var expected = lodashStable.map(falsey, stubFalse);
var actual = lodashStable.map(falsey, function(value, index) {
return index ? isElement(value) : isElement();
});
assert.deepStrictEqual(actual, expected);
assert.strictEqual(isElement(args), false);
assert.strictEqual(isElement([1, 2, 3]), false);
assert.strictEqual(isElement(true), false);
assert.strictEqual(isElement(new Date), false);
assert.strictEqual(isElement(new Error), false);
assert.strictEqual(isElement(_), false);
assert.strictEqual(isElement(slice), false);
assert.strictEqual(isElement({ 'a': 1 }), false);
assert.strictEqual(isElement(1), false);
assert.strictEqual(isElement(/x/), false);
assert.strictEqual(isElement('a'), false);
assert.strictEqual(isElement(symbol), false);
});
it('should return `false` for plain objects', function() {
assert.strictEqual(isElement({ 'nodeType': 1 }), false);
assert.strictEqual(isElement({ 'nodeType': Object(1) }), false);
assert.strictEqual(isElement({ 'nodeType': true }), false);
assert.strictEqual(isElement({ 'nodeType': [1] }), false);
assert.strictEqual(isElement({ 'nodeType': '1' }), false);
assert.strictEqual(isElement({ 'nodeType': '001' }), false);
});
it('should work with a DOM element from another realm', function() {
if (realm.element) {
assert.strictEqual(isElement(realm.element), true);
}
});
});