Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix Dates inside isEmptyObjectOrArray helper #22

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, beforeEach, it, mock } from "bun:test";
import { beforeEach, describe, expect, it, mock } from "bun:test";
import { defaultComposer, setConfig } from ".";

type Address = {
Expand Down Expand Up @@ -309,4 +309,22 @@ describe("defaultComposer", () => {

expect(defaultComposer<any>(defaults, object)).toEqual(expected);
});

it('should respect the Date object', () => {
const defaults = {
date: new Date(),
};

const object = {
date: new Date(2020, 1, 1),
anotherDate: new Date(2020, 2, 1),
};

const expected = {
date: new Date(2020, 1, 1),
anotherDate: new Date(2020, 2, 1),
};

expect(defaultComposer<any>(defaults, object)).toEqual(expected);
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function isObject(value: any): boolean {
}

function isEmptyObjectOrArray<T>(object: T): boolean {
if (typeof object !== "object" || object === null) return false;
if (typeof object !== "object" || object === null || object instanceof Date) return false;
return getAllKeys(object).length === 0;
}

Expand Down