diff --git a/src/test/calendar_test.test.tsx b/src/test/calendar_test.test.tsx index 9bf6d34e9..e3c2cae9b 100644 --- a/src/test/calendar_test.test.tsx +++ b/src/test/calendar_test.test.tsx @@ -36,6 +36,7 @@ import DatePicker from "../index"; import { getKey, + getRandomMonthExcludingCurrent, SafeElementWrapper, safeQuerySelector, safeQuerySelectorAll, @@ -1287,11 +1288,10 @@ describe("Calendar", () => { .safeQuerySelector("select") .getElement(); + const month = getRandomMonthExcludingCurrent(); fireEvent.change(select, { target: { - value: Array.from( - select.querySelectorAll("option"), - ).at(-2)?.value, + value: month, }, }); diff --git a/src/test/test_utils.ts b/src/test/test_utils.ts index 5e576795b..54f8073c5 100644 --- a/src/test/test_utils.ts +++ b/src/test/test_utils.ts @@ -68,6 +68,17 @@ export const range = (from: number, to: number): number[] => { return list; }; +export const getRandomMonthExcludingCurrent = (): number => { + const currentMonth = new Date().getMonth(); + + let randomMonth; + do { + randomMonth = Math.floor(Math.random() * 12); + } while (randomMonth === currentMonth); + + return randomMonth; +}; + export const openDateInput = (container: Element) => { const dateInput = container.querySelector("input")!; fireEvent.focus(dateInput);