Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enzyme to RTL (some files) #4572

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions test/day_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { es } from "date-fns/locale";
import Day from "../src/day";
import { mount } from "enzyme";
import {
getDayOfWeekCode,
newDate,
Expand Down Expand Up @@ -30,7 +29,7 @@ describe("Day", () => {

it("should apply the day of week class", () => {
let day = newDate();
for (var i = 0; i < 7; i++) {
for (let i = 0; i < 7; i++) {
const className = "react-datepicker__day--" + getDayOfWeekCode(day);
const container = renderDay(day);
expect(
Expand Down Expand Up @@ -1178,7 +1177,7 @@ describe("Day", () => {
});

describe("click", () => {
var onClickCalled;
let onClickCalled;

function onClick() {
onClickCalled = true;
Expand Down Expand Up @@ -1414,26 +1413,53 @@ describe("Day", () => {
jest.resetAllMocks();
});

it("should apply focus to the preselected day", () => {
it("should apply focus to the preselected day", async () => {
const day = newDate();
const dayInstance = mount(
<Day day={day} preSelection={day} />,
).instance();
let instance;
render(
<Day
ref={(node) => {
instance = node;
}}
day={day}
preSelection={day}
/>,
);

const focusSpy = jest
.spyOn(instance.dayEl.current, "focus")
.mockImplementation();
Object.defineProperty(document, "activeElement", {
value: undefined,
writable: false,
});

jest.spyOn(dayInstance.dayEl.current, "focus");
dayInstance.componentDidMount();
expect(dayInstance.dayEl.current.focus).toHaveBeenCalledTimes(1);
instance.componentDidMount();
expect(focusSpy).toHaveBeenCalledTimes(1);
});

it("should not apply focus to the preselected day if inline", () => {
const day = newDate();
const dayInstance = mount(
<Day day={day} preSelection={day} inline />,
).instance();
let instance;
render(
<Day
ref={(node) => {
instance = node;
}}
day={day}
preSelection={day}
inline
/>,
);

const focusSpy = jest.spyOn(instance.dayEl.current, "focus");
Object.defineProperty(document, "activeElement", {
value: undefined,
writable: false,
});

jest.spyOn(dayInstance.dayEl.current, "focus");
dayInstance.componentDidMount();
expect(dayInstance.dayEl.current.focus).not.toHaveBeenCalledTimes(1);
instance.componentDidMount();
expect(focusSpy).not.toHaveBeenCalledTimes(1);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/helper_components/custom_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from "prop-types";

class CustomInput extends React.Component {
onChange = (e) => {
var args = [e, e.target.value];
let args = [e, e.target.value];
if (this.props.onChangeArgs) {
args = this.props.onChangeArgs(e);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";

var TestWrapper = ({ className, children }) => (
const TestWrapper = ({ className, children }) => (
<div className={classNames("test-wrapper", className)}>{children}</div>
);

Expand Down
Loading
Loading