wimi/test/ErrorRenderer.test.tsx

27 lines
789 B
TypeScript
Raw 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", () => {
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(() => {
global.chrome = undefined;
});
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
});
});