From 894fe39d4a8670ad58be32c5dbfe7e36776cb264 Mon Sep 17 00:00:00 2001 From: yuki0410-dev Date: Sat, 8 Jun 2024 21:46:55 +0900 Subject: [PATCH] fix src/test/month_dropdown_test.test.tsx --- jest.config.js | 3 +-- src/test/month_dropdown_test.test.tsx | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/jest.config.js b/jest.config.js index b86f7ad8c..a82d8cf7a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,7 +3,6 @@ const babelTargetList = [ "calendar_test\\.test\\.tsx", "datepicker_test\\.test\\.tsx", "min_time_test\\.test\\.tsx", - "month_dropdown_test\\.test\\.tsx", "month_test\\.test\\.tsx", "multi_month_test\\.test\\.tsx", "multiple_selected_dates\\.test\\.tsx", @@ -28,7 +27,7 @@ const tsTargetList = [ "index\\.ts", "inject_times_test\\.test\\.tsx", // "min_time_test\\.test\\.tsx", - // "month_dropdown_test\\.test\\.tsx", + "month_dropdown_test\\.test\\.tsx", // "month_test\\.test\\.tsx", "month_year_dropdown_test\\.test\\.tsx", // "multi_month_test\\.test\\.tsx", diff --git a/src/test/month_dropdown_test.test.tsx b/src/test/month_dropdown_test.test.tsx index 9debe3477..e1c1ce5cb 100644 --- a/src/test/month_dropdown_test.test.tsx +++ b/src/test/month_dropdown_test.test.tsx @@ -2,7 +2,6 @@ import { render, fireEvent } from "@testing-library/react"; import { el } from "date-fns/locale/el"; import { ru } from "date-fns/locale/ru"; import { zhCN } from "date-fns/locale/zh-CN"; -import range from "lodash/range"; import React from "react"; import onClickOutside from "react-onclickoutside"; @@ -10,14 +9,23 @@ import { getMonthInLocale, registerLocale } from "../date_utils"; import MonthDropdown from "../month_dropdown"; import MonthDropdownOptions from "../month_dropdown_options"; +import { range } from "./test_utils"; + +type MonthDropdownProps = React.ComponentProps; + describe("MonthDropdown", () => { let monthDropdown: HTMLElement | null = null; - let handleChangeResult; - const mockHandleChange = function (changeInput) { + let handleChangeResult: number | null; + const mockHandleChange = function (changeInput: number) { handleChangeResult = changeInput; }; - function getMonthDropdown(overrideProps?) { + function getMonthDropdown( + overrideProps?: Partial< + Pick + > & + Omit, + ) { return render( { ); fireEvent.click( (monthDropdown?.querySelectorAll(".react-datepicker__month-option") ?? - [])[1], + [])[1] ?? new HTMLElement(), ); expect( monthDropdown?.querySelectorAll(".react-datepicker__month-dropdown"), @@ -137,7 +145,7 @@ describe("MonthDropdown", () => { ); fireEvent.click( (monthDropdown?.querySelectorAll(".react-datepicker__month-option") ?? - [])[11], + [])[11] ?? new HTMLElement(), ); expect(handleChangeResult).toBeNull(); }); @@ -149,7 +157,7 @@ describe("MonthDropdown", () => { ); fireEvent.click( (monthDropdown?.querySelectorAll(".react-datepicker__month-option") ?? - [])[2], + [])[2] ?? new HTMLElement(), ); expect(handleChangeResult).toEqual(2); });