Skip to content

Commit 2fc0033

Browse files
refactor: replace fireEvent with userEvent in unit tests (#732)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: huyenltnguyen <25715018+huyenltnguyen@users.noreply.github.com>
1 parent 8c34f4a commit 2fc0033

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/quiz-question/quiz-question.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { render, screen, within, fireEvent } from "@testing-library/react";
2+
import { render, screen, within } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44

55
import { QuizQuestion } from "./quiz-question";
@@ -301,7 +301,7 @@ describe("<QuizQuestion />", () => {
301301
).not.toBeInTheDocument();
302302
});
303303

304-
it("should render action buttons when provided", () => {
304+
it("should render action buttons when provided", async () => {
305305
const handleAction1 = jest.fn();
306306
const handleAction2 = jest.fn();
307307

@@ -353,10 +353,10 @@ describe("<QuizQuestion />", () => {
353353
"quiz-answer-2-label",
354354
);
355355

356-
fireEvent.click(actionButton1);
356+
await userEvent.click(actionButton1);
357357
expect(handleAction1).toHaveBeenCalledTimes(1);
358358

359-
fireEvent.click(actionButton2);
359+
await userEvent.click(actionButton2);
360360
expect(handleAction2).toHaveBeenCalledTimes(1);
361361

362362
// Verify no action button for option 3

src/quiz-question/transcript/transcript.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
2-
import { render, screen, fireEvent } from "@testing-library/react";
2+
import { render, screen } from "@testing-library/react";
3+
import userEvent from "@testing-library/user-event";
34

45
import { Transcript } from "./transcript";
56

@@ -25,34 +26,34 @@ describe("<Transcript />", () => {
2526
expect(screen.getByText("Sample transcript text")).not.toBeVisible();
2627
});
2728

28-
it("should toggle open when clicking the summary", () => {
29+
it("should toggle open when clicking the summary", async () => {
2930
render(<Transcript {...baseProps} />);
3031

3132
const summary = screen.getByText("Transcript");
32-
fireEvent.click(summary);
33+
await userEvent.click(summary);
3334

3435
const details = screen.getByRole("group");
3536
expect(details).toHaveAttribute("open");
3637
expect(screen.getByText("Sample transcript text")).toBeVisible();
3738
});
3839

39-
it("should filter out empty lines", () => {
40+
it("should filter out empty lines", async () => {
4041
const transcript = `Hello\n\n\nWorld\n \n`;
4142
render(<Transcript transcript={transcript} />);
4243

43-
fireEvent.click(screen.getByText("Transcript"));
44+
await userEvent.click(screen.getByText("Transcript"));
4445

4546
const paragraphs = screen.getAllByText(/Hello|World/);
4647
expect(paragraphs).toHaveLength(2);
4748
expect(paragraphs[0]).toHaveTextContent("Hello");
4849
expect(paragraphs[1]).toHaveTextContent("World");
4950
});
5051

51-
it("should render speaker names in bold", () => {
52+
it("should render speaker names in bold", async () => {
5253
const transcript = `Tom: Hello there!\nMaria: Hi Tom, how are you?`;
5354
render(<Transcript transcript={transcript} />);
5455

55-
fireEvent.click(screen.getByText("Transcript"));
56+
await userEvent.click(screen.getByText("Transcript"));
5657

5758
const tomElement = screen.getByText("Tom:");
5859
const mariaElement = screen.getByText("Maria:");

0 commit comments

Comments
 (0)