Skip to content

[#1807] Added ThemeProvider for tests #1808

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

Merged
merged 2 commits into from
Mar 18, 2021
Merged
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
14 changes: 10 additions & 4 deletions client/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/**
* This file re-exports @testing-library but ensures that
* any calls to render have translations available.
* any calls to render have translations and theme available.
*
* This means tested components will be able to call
* `t()` and have the translations of the default
* language
* language also components will be able to call
* `prop()` and have the theming of the default theme.
*
* See: https://react.i18next.com/misc/testing#testing-without-stubbing
* For i18n see: https://react.i18next.com/misc/testing#testing-without-stubbing
*/

// eslint-disable-next-line import/no-extraneous-dependencies
Expand All @@ -15,15 +16,20 @@ import React from 'react';
import PropTypes from 'prop-types';

import { I18nextProvider } from 'react-i18next';
import { ThemeProvider } from 'styled-components';

import i18n from './i18n-test';
import theme, { Theme } from './theme';

// re-export everything
// eslint-disable-next-line import/no-extraneous-dependencies
export * from '@testing-library/react';

const Providers = ({ children }) => (
// eslint-disable-next-line react/jsx-filename-extension
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
<ThemeProvider theme={{ ...theme[Theme.light] }}>
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
</ThemeProvider>
);

Providers.propTypes = {
Expand Down