-
Notifications
You must be signed in to change notification settings - Fork 23
/
utils.test.ts
37 lines (36 loc) 路 1.46 KB
/
utils.test.ts
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
import { it, expect } from "vitest";
import { isPlainObject } from "../src/_utils";
it("isPlainObject", () => {
expect(isPlainObject(undefined)).toBe(false);
expect(isPlainObject(0)).toBe(false);
expect(isPlainObject(0n)).toBe(false);
expect(isPlainObject("")).toBe(false);
expect(isPlainObject(true)).toBe(false);
expect(isPlainObject(Symbol(""))).toBe(false);
expect(isPlainObject(() => {})).toBe(false);
expect(isPlainObject(function namedFunc() {})).toBe(false);
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject({})).toBe(true);
expect(isPlainObject(Math)).toBe(false);
expect(isPlainObject(new Set([]))).toBe(false);
expect(isPlainObject(new ArrayBuffer(0))).toBe(false);
expect(isPlainObject(Promise.resolve())).toBe(false);
expect(isPlainObject(Object.create(null))).toBe(true);
expect(isPlainObject(new Intl.Locale("en"))).toBe(false);
// eslint-disable-next-line no-new-object
expect(isPlainObject(new Object({ prop: true }))).toBe(true);
expect(isPlainObject(new (class Class {})())).toBe(false);
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(/regexp/)).toBe(false);
expect(isPlainObject(new Error("test"))).toBe(false);
expect(isPlainObject(new Date())).toBe(false);
expect(
isPlainObject(
(function () {
// eslint-disable-next-line prefer-rest-params
return arguments;
})(),
),
).toBe(false);
// expect(isPlainObject(new Proxy({}, {}))).toBe(false); // TODO
});