Created
December 18, 2021 06:01
-
-
Save snbk97/e10048bdacaf3fe66b514a5d484b00d0 to your computer and use it in GitHub Desktop.
React Testing Library render with React-Intl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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