Skip to content

Instantly share code, notes, and snippets.

@snbk97
Created December 18, 2021 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snbk97/e10048bdacaf3fe66b514a5d484b00d0 to your computer and use it in GitHub Desktop.
Save snbk97/e10048bdacaf3fe66b514a5d484b00d0 to your computer and use it in GitHub Desktop.
React Testing Library render with React-Intl
import { ReactElement } from 'react';
import { render } from "@testing-library/react";
import { IntlProvider } from 'react-intl';
import EN from '../../locales/en-US'
import SW from '../../locales/sw-SW'
type ILang = 'en' | 'sw';
const langOptions = {
en: {
locale: EN.locale,
messages: EN.messages
},
sw: {
locale: SW.locale,
messages: SW.messages
}
}
const renderWithReactIntl = (component:ReactElement, lang:ILang) => {
const langProvider = langOptions[lang];
const {locale, messages} = langProvider;
return(
render(
<IntlProvider locale={locale} messages={messages}>
{component}
</IntlProvider>
)
)
};
export default renderWithReactIntl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment