Skip to content

Commit

Permalink
♻️ Update the test cases to use RTL based on the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Balaji Sridharan committed Feb 26, 2024
1 parent 6e4861f commit 6b82aaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 9 additions & 8 deletions test/month_test.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import ReactDOM from "react-dom";
import { render, fireEvent } from "@testing-library/react";
import Month from "../src/month";
import Day from "../src/day";
import DatePicker from "../src";
Expand Down Expand Up @@ -941,23 +941,24 @@ describe("Month", () => {
it("should call onKeyDown handler on any key press", () => {
const onKeyDownSpy = jest.fn();

const datePicker = TestUtils.renderIntoDocument(
const { container } = render(
<DatePicker
selected={new Date()}
dateFormat="MM/yyyy"
showMonthYearPicker
onKeyDown={onKeyDownSpy}
/>,
);
TestUtils.Simulate.focus(ReactDOM.findDOMNode(datePicker.input));

const month = TestUtils.findRenderedDOMComponentWithClass(
datePicker,
"react-datepicker__month-0",
);
TestUtils.Simulate.keyDown(month, {
const dateInput = container.querySelector("input");
fireEvent.focus(dateInput);

const month = container.querySelector(".react-datepicker__month-0");

fireEvent.keyDown(month, {
key: "ArrowDown",
});

expect(onKeyDownSpy).toHaveBeenCalledTimes(1);
});
});
Expand Down
15 changes: 7 additions & 8 deletions test/year_picker_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DatePicker from "../src/index.jsx";
import Year from "../src/year.jsx";
import TestUtils from "react-dom/test-utils";
import ReactDOM from "react-dom";
import { render, fireEvent } from "@testing-library/react";
import * as utils from "../src/date_utils.js";
import Calendar from "../src/calendar.jsx";
import { getKey } from "./test_utils.js";
Expand Down Expand Up @@ -602,23 +603,21 @@ describe("YearPicker", () => {
it("should call onKeyDown handler on any key press", () => {
const onKeyDownSpy = jest.fn();

const datePicker = TestUtils.renderIntoDocument(
const { container } = render(
<DatePicker
selected={new Date()}
showYearPicker
dateFormat="yyyy"
onKeyDown={onKeyDownSpy}
/>,
);
TestUtils.Simulate.focus(ReactDOM.findDOMNode(datePicker.input));

const yearPicker = TestUtils.findRenderedDOMComponentWithClass(
datePicker,
"react-datepicker__year-wrapper",
);
const dateInput = container.querySelector("input");
fireEvent.focus(dateInput);

const year = container.querySelector(".react-datepicker__year-text");

const year = yearPicker.children[0];
TestUtils.Simulate.keyDown(year, {
fireEvent.keyDown(year, {
key: "ArrowDown",
});

Expand Down

0 comments on commit 6b82aaf

Please sign in to comment.