-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
46 lines (40 loc) · 1.29 KB
/
test.js
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
42
43
44
45
46
import {runInNewContext} from 'node:vm';
import test from 'ava';
import isPlainObject from './index.js';
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)));
// eslint-disable-next-line no-object-constructor
t.true(isPlainObject(new Object()));
t.true(isPlainObject(runInNewContext('({})')));
t.false(isPlainObject(['foo', 'bar']));
t.false(isPlainObject(new Foo(1)));
t.false(isPlainObject(Math));
t.false(isPlainObject(JSON));
t.false(isPlainObject(Atomics));
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()));
t.false(isPlainObject(Object.create({})));
(function () {
t.false(isPlainObject(arguments)); // eslint-disable-line prefer-rest-params
})();
const foo = new Foo();
foo.constructor = Object;
t.false(isPlainObject(foo));
});