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

Fix jest unit test #1495

Merged
merged 2 commits into from
Feb 12, 2023
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
34 changes: 34 additions & 0 deletions website/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
// jest.setup.js
import "@testing-library/jest-dom/extend-expect";

const CONSOLE_FAIL_TYPES = ["error", "warn"];

// Throw errors when a `console.error` or `console.warn` happens
// by overriding the functions.
// If the warning/error is intentional, then catch it and expect for it, like:
//
// jest.spyOn(console, 'warn').mockImplementation();
// ...
// expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('Empty titles are deprecated.'));
CONSOLE_FAIL_TYPES.forEach((type) => {
const orig_f = console[type];
console[type] = (...message) => {
orig_f(...message);
throw new Error(`Failing due to console.${type} while running test!\n\n${message.join(" ")}`);
};
});

// Mock out useTranslation hook as per https://react.i18next.com/misc/testing
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) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
};
},
initReactI18next: {
type: "3rdParty",
init: () => {},
},
}));
5 changes: 0 additions & 5 deletions website/src/setupTests.js

This file was deleted.