Skip to content

Commit 8389812

Browse files
Fix lint violations in date utils tests
1 parent c592381 commit 8389812

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

src/test/date_utils_test.test.ts

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,41 @@ describe("date_utils", () => {
926926
});
927927
});
928928

929+
describe("isTimeInDisabledRange edge cases", () => {
930+
it("throws when either minTime or maxTime is missing", () => {
931+
expect(() =>
932+
isTimeInDisabledRange(newDate(), { minTime: newDate() }),
933+
).toThrow("Both minTime and maxTime props required");
934+
});
935+
936+
it("returns false when isWithinInterval throws", async () => {
937+
jest.doMock("date-fns", () => {
938+
const actual = jest.requireActual("date-fns");
939+
return {
940+
...actual,
941+
isWithinInterval: () => {
942+
throw new Error("boom");
943+
},
944+
};
945+
});
946+
947+
try {
948+
const { isTimeInDisabledRange: mockedIsTimeInDisabledRange } =
949+
await import("../date_utils");
950+
951+
expect(
952+
mockedIsTimeInDisabledRange(new Date(), {
953+
minTime: new Date(),
954+
maxTime: new Date(),
955+
}),
956+
).toBe(false);
957+
} finally {
958+
jest.resetModules();
959+
jest.dontMock("date-fns");
960+
}
961+
});
962+
});
963+
929964
describe("isDayInRange", () => {
930965
it("should tell if day is in range", () => {
931966
const day = newDate("2016-02-15 09:40");
@@ -1157,42 +1192,6 @@ describe("date_utils", () => {
11571192
});
11581193
});
11591194

1160-
describe("isTimeInDisabledRange", () => {
1161-
it("throws when either minTime or maxTime is missing", () => {
1162-
expect(() =>
1163-
isTimeInDisabledRange(newDate(), { minTime: newDate() }),
1164-
).toThrow("Both minTime and maxTime props required");
1165-
});
1166-
1167-
it("returns false when isWithinInterval throws", () => {
1168-
jest.isolateModules(() => {
1169-
jest.doMock("date-fns", () => {
1170-
const actual = jest.requireActual("date-fns");
1171-
return {
1172-
...actual,
1173-
isWithinInterval: () => {
1174-
throw new Error("boom");
1175-
},
1176-
};
1177-
});
1178-
1179-
// eslint-disable-next-line @typescript-eslint/no-var-requires -- isolated mock import
1180-
const {
1181-
isTimeInDisabledRange: mockedIsTimeInDisabledRange,
1182-
} = require("../date_utils");
1183-
expect(
1184-
mockedIsTimeInDisabledRange(new Date(), {
1185-
minTime: new Date(),
1186-
maxTime: new Date(),
1187-
}),
1188-
).toBe(false);
1189-
1190-
jest.resetModules();
1191-
jest.dontMock("date-fns");
1192-
});
1193-
});
1194-
});
1195-
11961195
describe("isYearInRange", () => {
11971196
it("should return true if the year passed is in range", () => {
11981197
const startDate = newDate("2000-01-01");
@@ -1632,31 +1631,33 @@ describe("date_utils", () => {
16321631
});
16331632

16341633
describe("isDayInRange error handling", () => {
1635-
it("returns false when isWithinInterval throws", () => {
1636-
jest.isolateModules(() => {
1637-
jest.doMock("date-fns", () => {
1638-
const actual = jest.requireActual("date-fns");
1639-
return {
1640-
...actual,
1641-
isWithinInterval: () => {
1642-
throw new Error("boom");
1643-
},
1644-
};
1645-
});
1646-
1647-
// eslint-disable-next-line @typescript-eslint/no-var-requires -- isolated mock import
1648-
const { isDayInRange: mockedIsDayInRange } = require("../date_utils");
1634+
it("returns false when isWithinInterval throws", async () => {
1635+
jest.doMock("date-fns", () => {
1636+
const actual = jest.requireActual("date-fns");
1637+
return {
1638+
...actual,
1639+
isWithinInterval: () => {
1640+
throw new Error("boom");
1641+
},
1642+
};
1643+
});
1644+
1645+
try {
1646+
const { isDayInRange: mockedIsDayInRange } = await import(
1647+
"../date_utils"
1648+
);
1649+
16491650
expect(
16501651
mockedIsDayInRange(
16511652
new Date("2024-01-15"),
16521653
new Date("2024-01-10"),
16531654
new Date("2024-01-20"),
16541655
),
16551656
).toBe(false);
1656-
1657+
} finally {
16571658
jest.resetModules();
16581659
jest.dontMock("date-fns");
1659-
});
1660+
}
16601661
});
16611662

16621663
it("returns true for dates inside a valid range", () => {

0 commit comments

Comments
 (0)