Skip to content

Commit

Permalink
add i18next mocks to tests (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
jollyjerr authored Apr 30, 2021
1 parent 5f7e57f commit a224c16
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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

0 comments on commit a224c16

Please sign in to comment.