From 83ad168cfe0f5865c4538e0b9bb98173e0c0a07e Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Thu, 14 Jul 2022 09:12:52 +0400 Subject: Wrap Tests In Act Wrap the tests that were raising warnings in act statements. Signed-off-by: Hassan Abouelela --- src/tests/pages/LandingPage.test.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/tests/pages/LandingPage.test.tsx') diff --git a/src/tests/pages/LandingPage.test.tsx b/src/tests/pages/LandingPage.test.tsx index 727b922..b2a5142 100644 --- a/src/tests/pages/LandingPage.test.tsx +++ b/src/tests/pages/LandingPage.test.tsx @@ -1,11 +1,11 @@ import React from "react"; -import { render, waitFor } from "@testing-library/react"; +import {act, render, screen} from "@testing-library/react"; import LandingPage from "../../pages/LandingPage"; import * as forms from "../../api/forms"; -import { MemoryRouter } from "react-router-dom"; -import { QuestionType } from "../../api/question"; +import {MemoryRouter} from "react-router-dom"; +import {QuestionType} from "../../api/question"; const testingForm: forms.Form = { "id": "testing-form", @@ -27,10 +27,7 @@ const testingForm: forms.Form = { test("renders landing page", async () => { jest.spyOn(forms, "getForms").mockImplementation(() => Promise.resolve([testingForm])); - - const { getByText } = render(, {wrapper: MemoryRouter}); - await waitFor(() => { - const headerBar = getByText(/Python Discord Forms/); - expect(headerBar).toBeInTheDocument(); - }); + act(() => { render(, {wrapper: MemoryRouter}); }); + const headerBar = await screen.findByText(/Python Discord Forms/); + expect(headerBar).toBeInTheDocument(); }); -- cgit v1.2.3 From 38a319d5a648978bf81e5a4c9548eab228af9665 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Thu, 14 Jul 2022 10:32:13 +0400 Subject: Fix Failing jest.spyOn Version 1.2.206 of swc introduces a breaking change which makes jest.spyOn not work with our configuration. The response from the swc maintainer seems like a complete mess, so I won't touch it, and just use something else. See issue 5059 on https://github.com/swc-project/swc/issues Signed-off-by: Hassan Abouelela --- src/tests/pages/LandingPage.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/tests/pages/LandingPage.test.tsx') diff --git a/src/tests/pages/LandingPage.test.tsx b/src/tests/pages/LandingPage.test.tsx index b2a5142..908feed 100644 --- a/src/tests/pages/LandingPage.test.tsx +++ b/src/tests/pages/LandingPage.test.tsx @@ -25,8 +25,12 @@ const testingForm: forms.Form = { submitted_text: null }; +jest.mock("../../api/forms", () => ({ + ...jest.requireActual("../../api/forms"), + getForms: jest.fn(() => Promise.resolve([testingForm])) +})); + test("renders landing page", async () => { - jest.spyOn(forms, "getForms").mockImplementation(() => Promise.resolve([testingForm])); act(() => { render(, {wrapper: MemoryRouter}); }); const headerBar = await screen.findByText(/Python Discord Forms/); expect(headerBar).toBeInTheDocument(); -- cgit v1.2.3