Skip to content

Commit

Permalink
Merge pull request Hacker0x01#5039 from qburst/issue-5038/refactor/te…
Browse files Browse the repository at this point in the history
…st/ensure-element-existance

Fix Hacker0x01#5038: Enhance test case querySelector/querySelectorAll reliability with ensuring element existance
  • Loading branch information
martijnrusschen authored Aug 28, 2024
2 parents 35fb058 + 767c3b9 commit 000bbd9
Show file tree
Hide file tree
Showing 18 changed files with 1,075 additions and 570 deletions.
21 changes: 13 additions & 8 deletions src/test/calendar_icon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";
import CalendarIcon from "../calendar_icon";

import { IconParkSolidApplication } from "./helper_components/calendar_icon";
import { safeQuerySelector } from "./test_utils";

describe("CalendarIcon", () => {
let onClickMock: jest.Mock;
Expand Down Expand Up @@ -38,9 +39,11 @@ describe("CalendarIcon", () => {
it("should fire onClick event when the icon is clicked", () => {
const { container } = render(<CalendarIcon onClick={onClickMock} />);

const icon = container.querySelector("svg.react-datepicker__calendar-icon");
expect(icon).not.toBeNull();
fireEvent.click(icon ?? new Element());
const icon = safeQuerySelector(
container,
"svg.react-datepicker__calendar-icon",
);
fireEvent.click(icon);

expect(onClickMock).toHaveBeenCalledTimes(1);
});
Expand All @@ -50,9 +53,8 @@ describe("CalendarIcon", () => {
<CalendarIcon icon="fa-example-icon" onClick={onClickMock} />,
);

const icon = container.querySelector("i.fa-example-icon");
expect(icon).not.toBeNull();
fireEvent.click(icon ?? new Element());
const icon = safeQuerySelector(container, "i.fa-example-icon");
fireEvent.click(icon);

expect(onClickMock).toHaveBeenCalledTimes(1);
});
Expand All @@ -75,8 +77,11 @@ describe("CalendarIcon", () => {
/>,
);

const icon = container.querySelector("svg.react-datepicker__calendar-icon");
fireEvent.click(icon ?? new Element());
const icon = safeQuerySelector(
container,
"svg.react-datepicker__calendar-icon",
);
fireEvent.click(icon);

expect(onClickMock).toHaveBeenCalledTimes(1);
expect(onClickCustomIcon).toHaveBeenCalledTimes(1);
Expand Down
Loading

0 comments on commit 000bbd9

Please sign in to comment.