|
| 1 | +import { it, expect } from "vitest"; |
| 2 | +import { isPlainObject } from "../src/_utils"; |
| 3 | + |
| 4 | +it("isPlainObject", () => { |
| 5 | + expect(isPlainObject(undefined)).toBe(false); |
| 6 | + expect(isPlainObject(0)).toBe(false); |
| 7 | + expect(isPlainObject(0n)).toBe(false); |
| 8 | + expect(isPlainObject("")).toBe(false); |
| 9 | + expect(isPlainObject(true)).toBe(false); |
| 10 | + expect(isPlainObject(Symbol(""))).toBe(false); |
| 11 | + expect(isPlainObject(() => {})).toBe(false); |
| 12 | + expect(isPlainObject(function namedFunc() {})).toBe(false); |
| 13 | + expect(isPlainObject(null)).toBe(false); |
| 14 | + expect(isPlainObject({})).toBe(true); |
| 15 | + expect(isPlainObject(Math)).toBe(false); |
| 16 | + expect(isPlainObject(new Set([]))).toBe(false); |
| 17 | + expect(isPlainObject(new ArrayBuffer(0))).toBe(false); |
| 18 | + expect(isPlainObject(Promise.resolve())).toBe(false); |
| 19 | + expect(isPlainObject(Object.create(null))).toBe(true); |
| 20 | + expect(isPlainObject(new Intl.Locale("en"))).toBe(false); |
| 21 | + // eslint-disable-next-line no-new-object |
| 22 | + expect(isPlainObject(new Object({ prop: true }))).toBe(true); |
| 23 | + expect(isPlainObject(new (class Class {})())).toBe(false); |
| 24 | + expect(isPlainObject([])).toBe(false); |
| 25 | + expect(isPlainObject(/regexp/)).toBe(false); |
| 26 | + expect(isPlainObject(new Error("test"))).toBe(false); |
| 27 | + expect(isPlainObject(new Date())).toBe(false); |
| 28 | + expect( |
| 29 | + isPlainObject( |
| 30 | + (function () { |
| 31 | + // eslint-disable-next-line prefer-rest-params |
| 32 | + return arguments; |
| 33 | + })(), |
| 34 | + ), |
| 35 | + ).toBe(false); |
| 36 | + // expect(isPlainObject(new Proxy({}, {}))).toBe(false); // TODO |
| 37 | +}); |
0 commit comments