diff --git a/test/defu.test.ts b/test/defu.test.ts index 7f12aa2..19d490d 100644 --- a/test/defu.test.ts +++ b/test/defu.test.ts @@ -50,7 +50,7 @@ describe("defu", () => { }>(); }); - it.skip("should avoid merging objects with custom constructor", () => { + it("should avoid merging objects with custom constructor", () => { class Test { // eslint-disable-next-line no-useless-constructor constructor(public value: string) {} @@ -59,11 +59,11 @@ describe("defu", () => { expect(result).toEqual({ test: new Test("a") }); }); - it.skip("should assign date properly", () => { + it("should assign date properly", () => { const date1 = new Date("2020-01-01"); const date2 = new Date("2020-01-02"); const result = defu({ date: date1 }, { date: date2 }); - expect(result).toEqual({ date: date2 }); + expect(result).toEqual({ date: date1 }); }); it("should correctly merge different object types", () => { diff --git a/test/utils.test.ts b/test/utils.test.ts new file mode 100644 index 0000000..3dcef5b --- /dev/null +++ b/test/utils.test.ts @@ -0,0 +1,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 +});