From 79590b72114bf907663845409eba4756f2ce7fe9 Mon Sep 17 00:00:00 2001 From: Balaji Sridharan Date: Sat, 14 Oct 2023 22:19:22 +0530 Subject: [PATCH 1/2] fix: Fix Enzyme Test file in exclude_times_test.js In the exclude_times_test.js file, the following modifications were made to improve the test case: 1. Added the 'open' prop to the component to ensure that it is open and its children can be tested. 2. Corrected the call to 'setTime' by providing the correct parameter format, { hour: x, minute: x }, instead of { hours: x, minutes: x }. 3. Replaced the assertion using '.not.toBeNull()' with '.toHaveLength(4)' when using '.find()'. This change makes the assertion more specific and reliable, ensuring that the test case passes only when it should. These updates enhance the accuracy and reliability of the test case in the exclude_times_test.js file. Closes #4317 --- test/exclude_times_test.test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/exclude_times_test.test.js b/test/exclude_times_test.test.js index 6366392cf..221f5bafa 100644 --- a/test/exclude_times_test.test.js +++ b/test/exclude_times_test.test.js @@ -8,17 +8,18 @@ describe("DatePicker", () => { var now = newDate(); var datePicker = mount( , ); expect( datePicker.find(".react-datepicker__time-list-item--disabled"), - ).not.toBeNull(); + ).toHaveLength(4); }); }); From 5b82a9602ae8a2a4c598e2d418e97acb3d2638b6 Mon Sep 17 00:00:00 2001 From: Balaji Sridharan Date: Sat, 14 Oct 2023 22:34:28 +0530 Subject: [PATCH 2/2] Migrate Enzyme Test to @testing-library/react in exclude_times_test.js This commit updates the test case in exclude_times_test.js from using Enzyme to using @testing-library/react as requested by @martijnrusschen on [the issue #4317](https://github.com/Hacker0x01/react-datepicker/issues/4317#issuecomment-1763037871) --- test/exclude_times_test.test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/exclude_times_test.test.js b/test/exclude_times_test.test.js index 221f5bafa..71765a3de 100644 --- a/test/exclude_times_test.test.js +++ b/test/exclude_times_test.test.js @@ -1,12 +1,13 @@ import React from "react"; -import { mount } from "enzyme"; +import { render } from "@testing-library/react"; import { setTime, newDate } from "../src/date_utils"; import DatePicker from "../src/index.jsx"; describe("DatePicker", () => { it("should disable times specified in excludeTimes props", () => { - var now = newDate(); - var datePicker = mount( + const now = newDate(); + + const { container: datePicker } = render( { ]} />, ); - expect( - datePicker.find(".react-datepicker__time-list-item--disabled"), - ).toHaveLength(4); + + const disabledTimeItems = datePicker.querySelectorAll( + ".react-datepicker__time-list-item--disabled", + ); + expect(disabledTimeItems.length).toBe(4); }); });