ts
37 lines
1.05 KB
| 1 | /** |
| 2 | * Components using the react-intl module require access to the intl context. |
| 3 | * This is not available when mounting single components in Enzyme. |
| 4 | * These helper functions aim to address that and wrap a valid, |
| 5 | * English-locale intl context around them. |
| 6 | */ |
| 7 | |
| 8 | import React from 'react' |
| 9 | import { IntlProvider } from 'react-intl' |
| 10 | import { mount, shallow } from 'enzyme' |
| 11 | |
| 12 | // You can pass your messages to the IntlProvider. Optional: remove if unneeded. |
| 13 | import messages_en from "./../components/translations/en.json"; |
| 14 | const defaultLocale = 'en' |
| 15 | const locale = defaultLocale |
| 16 | |
| 17 | export function mountWithIntl(node: React.ReactElement) { |
| 18 | return mount(node, { |
| 19 | wrappingComponent: IntlProvider, |
| 20 | wrappingComponentProps: { |
| 21 | locale, |
| 22 | defaultLocale, |
| 23 | messages_en |
| 24 | } |
| 25 | }) |
| 26 | } |
| 27 | |
| 28 | export function shallowWithIntl(node: React.ReactElement) { |
| 29 | return shallow(node, { |
| 30 | wrappingComponent: IntlProvider, |
| 31 | wrappingComponentProps: { |
| 32 | locale, |
| 33 | defaultLocale, |
| 34 | messages_en |
| 35 | } |
| 36 | }) |
| 37 | } |