wimi/test/ErrorRenderer.test.tsx

28 lines
830 B
TypeScript
Raw Permalink Normal View History

2023-09-28 23:10:15 +02:00
import React from "react";
2023-09-29 20:25:24 +02:00
import '@testing-library/jest-dom';
2023-09-28 23:10:15 +02:00
import { render, screen } from "@testing-library/react";
import { ErrorRenderer } from "~/components/ErrorRenderer";
import { getMessage } from "./mocks/chrome.i18n";
describe("ErrorRenderer.tsx", () => {
2024-08-03 10:01:20 +02:00
const globalChrome = global.chrome;
2023-09-28 23:10:15 +02:00
const error = new Error("This is an example error message");
beforeEach(() => {
2023-09-29 20:25:24 +02:00
const chrome: any = { i18n: { getMessage } };
2023-09-28 23:10:15 +02:00
global.chrome = chrome;
render(<ErrorRenderer error={error}/>);
});
afterEach(() => {
2024-08-03 10:01:20 +02:00
global.chrome = globalChrome;
2023-09-28 23:10:15 +02:00
});
test("an error is rendered", () => {
2024-04-05 20:44:49 +02:00
const { getByTestId, getByText } = screen;
const span = getByTestId("error-message");
expect(getByText("Error")).toBeInTheDocument();
expect(span.textContent).toEqual(error.message);
2023-09-28 23:10:15 +02:00
});
});