Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add i18next mocks to tests #470

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/web/src/components/__tests__/BackButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { fireEvent, render } from "@testing-library/react";

import BackButton from "../BackButton";
import { I18nextProvider } from "react-i18next";
import React from "react";
import i18n from "../../i18n";
import { useHistory } from "react-router-dom";

jest.mock("react-router-dom", () => ({
Expand All @@ -12,7 +15,11 @@ const mockUseHistory = useHistory as jest.Mock;

describe("<BackButton/>", () => {
const setup = (overrides = {}) => {
return render(<BackButton {...overrides} />);
return render(
<I18nextProvider i18n={i18n}>
<BackButton {...overrides} />
</I18nextProvider>
);
};

it("calls the passed action when clicked", () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/components/__tests__/HomeButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ jest.mock("../HomeLink", () => ({
<div>{children}</div>
),
}));
jest.mock("react-i18next", () => ({
// this mock makes sure any components using the translate hook can use it without a warning being shown
useTranslation: () => {
return {
t: (str: string) => str,
i18n: {
changeLanguage: () => new Promise(() => ({})),
},
};
},
}));

describe("<HomeButtons/>", () => {
const routerLinkTexts = routerLinkButtons.map(
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/components/__tests__/Hotlines.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import Hotlines, { hotlineList } from "../Hotlines";

import React from "react";
import { render } from "@testing-library/react";

jest.mock("../HotlineCard", () => () => <div data-test="TEST-hotline-card" />);
jest.mock("../PageBanner", () => () => null);
jest.mock("react-i18next", () => ({
useTranslation: () => {
return {
t: (str: string) => str,
i18n: {
changeLanguage: () => new Promise(() => ({})),
},
};
},
}));

describe("<Hotlines/>", () => {
it("renders a hotline card for each hotline", () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/components/__tests__/Resource.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ jest.mock("../../App.styles", () => ({
},
},
}));
jest.mock("react-i18next", () => ({
// this mock makes sure any components using the translate hook can use it without a warning being shown
useTranslation: () => {
return {
t: (str: string) => str,
i18n: {
changeLanguage: () => new Promise(() => ({})),
},
};
},
}));

const mockUseResources = useResources as jest.Mock;

Expand Down