π OpenHands: AI-Driven Development
fix warnings during test runs (#1638)
sp.wack88ef414e3a96
diff --git a/frontend/src/components/chat/ChatInput.test.tsx b/frontend/src/components/chat/ChatInput.test.tsxindex 4ca14a2d45..60d79cd8da 100644--- a/frontend/src/components/chat/ChatInput.test.tsx+++ b/frontend/src/components/chat/ChatInput.test.tsx@@ -3,12 +3,6 @@ import userEvent from "@testing-library/user-event";import { act, render } from "@testing-library/react";import ChatInput from "./ChatInput";-const tMock = vi.fn((key: string) => key);--vi.mock("react-i18next", () => ({- useTranslation: () => ({ t: tMock }),-}));-describe("ChatInput", () => {const onSendMessage = vi.fn();@@ -39,14 +33,11 @@ describe("ChatInput", () => {expect(onSendMessage).not.toHaveBeenCalled();});- // Note that this test only checks that the placeholder is rendered, not the actual valueit("should render with a placeholder", () => {- tMock.mockReturnValue("value-returned-by-t");-const { getByPlaceholderText } = render(<ChatInput onSendMessage={onSendMessage} />,);- const textarea = getByPlaceholderText("value-returned-by-t");+ const textarea = getByPlaceholderText(/CHAT_INTERFACE\$INPUT_PLACEHOLDER/i);expect(textarea).toBeInTheDocument();});diff --git a/frontend/src/components/file-explorer/FileExplorer.test.tsx b/frontend/src/components/file-explorer/FileExplorer.test.tsxindex aeae2d6ba1..9ceb073906 100644--- a/frontend/src/components/file-explorer/FileExplorer.test.tsx+++ b/frontend/src/components/file-explorer/FileExplorer.test.tsx@@ -1,5 +1,5 @@import React from "react";-import { render, waitFor } from "@testing-library/react";+import { render, waitFor, screen } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { act } from "react-dom/test-utils";import { describe, it, expect, vi, Mock } from "vitest";@@ -59,11 +59,13 @@ describe("FileExplorer", () => {expect(onFileClickMock).toHaveBeenCalledWith(absPath);});- it("should refetch the workspace when clicking the refresh button", () => {- const { getByTestId } = render(<FileExplorer onFileClick={vi.fn} />);+ it("should refetch the workspace when clicking the refresh button", async () => {+ const onFileClickMock = vi.fn();+ render(<FileExplorer onFileClick={onFileClickMock} />);- act(() => {- userEvent.click(getByTestId("refresh"));+ // The 'await' keyword is required here to avoid a warning during test runs+ await act(() => {+ userEvent.click(screen.getByTestId("refresh"));});expect(getWorkspace).toHaveBeenCalledTimes(2); // 1 from initial render, 1 from refresh button@@ -87,13 +89,14 @@ describe("FileExplorer", () => {expect(queryByText("root")).not.toBeVisible();});- it("should upload a file", () => {+ it("should upload a file", async () => {const { getByTestId } = render(<FileExplorer onFileClick={vi.fn} />);const uploadFileInput = getByTestId("file-input");const file = new File([""], "test");- act(() => {+ // The 'await' keyword is required here to avoid a warning during test runs+ await act(() => {userEvent.upload(uploadFileInput, file);});diff --git a/frontend/src/components/modals/settings/SettingsModal.test.tsx b/frontend/src/components/modals/settings/SettingsModal.test.tsxindex 0351a5b4d0..f9e8210300 100644--- a/frontend/src/components/modals/settings/SettingsModal.test.tsx+++ b/frontend/src/components/modals/settings/SettingsModal.test.tsx@@ -80,14 +80,16 @@ describe("SettingsModal", () => {expect(onOpenChange).toHaveBeenCalledWith(false);});- it("should disabled the save button if the settings contain a missing value", () => {+ it("should disabled the save button if the settings contain a missing value", async () => {const onOpenChangeMock = vi.fn();(getSettings as Mock).mockReturnValueOnce({LLM_MODEL: "gpt-3.5-turbo",AGENT: "",});- renderWithProviders(- <SettingsModal isOpen onOpenChange={onOpenChangeMock} />,+ await act(async () =>+ renderWithProviders(+ <SettingsModal isOpen onOpenChange={onOpenChangeMock} />,+ ),);const saveButton = screen.getByRole("button", { name: /save/i });diff --git a/frontend/vitest.setup.ts b/frontend/vitest.setup.tsindex 7e3bc7a68f..ff5c8188b4 100644--- a/frontend/vitest.setup.ts+++ b/frontend/vitest.setup.ts@@ -1,3 +1,12 @@// learn more: https://github.com/testing-library/jest-dom// eslint-disable-next-line import/no-extraneous-dependenciesimport "@testing-library/jest-dom";++// @ts-expect-error - Mock for Terminal tests+HTMLCanvasElement.prototype.getContext = vi.fn();++// Mock the i18n provider+vi.mock("react-i18next", async (importOriginal) => ({+ ...(await importOriginal<typeof import("react-i18next")>()),+ useTranslation: () => ({ t: (key: string) => key }),+}));