Skip to content

Commit e8f2ca3

Browse files
committed
test: fix a test that would always fail if run on first day of month
1 parent e38003b commit e8f2ca3

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/test/exclude_dates.test.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { render } from "@testing-library/react";
2-
import { subDays } from "date-fns";
2+
import { addDays, subDays } from "date-fns";
33
import React from "react";
44

55
import DatePicker from "../index";
66

77
describe("DatePicker", () => {
8-
const excludeDates = [new Date(), subDays(new Date(), 1)];
8+
const today = new Date();
9+
// otherDate must be in same month, otherwise it will not be shown on the calendar
10+
const otherDate =
11+
today.getDate() === 1 ? addDays(today, 1) : subDays(today, 1);
12+
const excludeDates = [today, otherDate];
913
const excludeDatesWithMessages = [
10-
{ date: subDays(new Date(), 1), message: "This day is excluded" },
11-
{ date: new Date(), message: "Today is excluded" },
14+
{ date: otherDate, message: "This day is excluded" },
15+
{ date: today, message: "Today is excluded" },
1216
];
1317

1418
it("should disable dates specified in excludeDates props", () => {
@@ -40,11 +44,11 @@ describe("DatePicker", () => {
4044
);
4145

4246
expect(disabledTimeItems.length).toBe(excludeDatesWithMessages.length);
43-
expect(disabledTimeItems[0]?.getAttribute("title")).toBe(
44-
"This day is excluded",
45-
);
46-
expect(disabledTimeItems[1]?.getAttribute("title")).toBe(
47-
"Today is excluded",
48-
);
47+
expect(
48+
disabledTimeItems[today < otherDate ? 1 : 0]?.getAttribute("title"),
49+
).toBe("This day is excluded");
50+
expect(
51+
disabledTimeItems[today < otherDate ? 0 : 1]?.getAttribute("title"),
52+
).toBe("Today is excluded");
4953
});
5054
});

0 commit comments

Comments
 (0)