1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
const test = require('tape');
const isPlainObject = require('.');
function Foo(x) {
this.x = x;
}
function ObjectConstructor() {}
ObjectConstructor.prototype.constructor = Object;
test('main', t => {
t.true(isPlainObject({}));
t.true(isPlainObject({foo: true}));
t.true(isPlainObject({constructor: Foo}));
t.true(isPlainObject({valueOf: 0}));
t.true(isPlainObject(Object.create(null)));
t.true(isPlainObject(new Object())); // eslint-disable-line no-new-object
t.false(isPlainObject(['foo', 'bar']));
t.false(isPlainObject(new Foo(1)));
t.false(isPlainObject(Math));
t.false(isPlainObject(Error));
t.false(isPlainObject(() => {}));
t.false(isPlainObject(/./));
t.false(isPlainObject(null));
t.false(isPlainObject(undefined));
t.false(isPlainObject(Number.NaN));
t.false(isPlainObject(''));
t.false(isPlainObject(0));
t.false(isPlainObject(false));
t.false(isPlainObject(new ObjectConstructor()));
(function () {
t.false(isPlainObject(arguments)); // eslint-disable-line prefer-rest-params
})();
const foo = new Foo();
foo.constructor = Object;
t.false(isPlainObject(foo));
t.end();
});
|