Open Arrvi opened 5 years ago
On the top of Arrvi asked, react-intl has rewritten with Typescript in 3.x, could you also support Typescript natively?
You can make it work by using Enzyme's getWrappingComponent and IntlProvider
e.g
const defaultMessages = new Proxy({}, { get: (target, property) => property });
let messages = defaultMessages;
export function loadTranslationObject(translations: object): object {
if (typeof translations === 'undefined') {
messages = defaultMessages;
return defaultMessages;
}
messages = translations;
return messages;
}
const WrappingComponent: React.FC = ({ children }) => (
<IntlProvider locale="en" messages={messages}>
{children}
</IntlProvider>
);
export const mountWithIntl = (node: ReactElement) =>
mount(node, { wrappingComponent: WrappingComponent });
Is documented here officially: https://github.com/formatjs/react-intl/blob/master/docs/Testing-with-React-Intl.md#helper-function-1
This package is not compatible with current react-intl. When trying to mount, the function crashes on old API: