File: test.js

package info (click to toggle)
node-is-plain-obj 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 136 kB
  • sloc: javascript: 77; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (2)
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();
});