When using Enzyme and React-Intl you are likely run into the issues when testing components that use some of React-Intl's components or injected formatting functions. These helper functions (mountWithIntl
and shallowWithIntl
) aim to address some of the below errors:
Uncaught Invariant Violation: [React Intl] Could not find required ``intl`` object. <IntlProvider> needs to exist in the component ancestry.
TypeError: Cannot read property 'getInstance' of null
Error: ReactWrapper::state() can only be called on the root
Checkout this question at StackOverflow for a complete overview of the issues I ran into:
Injecting react-intl object into mounted Enzyme components for testing
Hello, thanks for the gist
This does not work for me if i have to use the injectIntl API in my component like:
this.props.intl.formatMessage(messages.MY_MESSAGE)}
With the component tested wrapped with injectIntl
But it does work for component that just use the react syntax:
<FormattedMessage {...messages.MY_MESSAGE} />
I'm looking into it, but if you have some inputs