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
I am having similar problems. See gist: https://gist.github.com/maniax89/62bddbfeefa2e368d37e7f3a9270bd6f
Basically this leads me to getting the
Invariant Violation: [React Intl] Could not find required
intlobject. <IntlProvider> needs to exist in the component ancestry.
I believe it is because I have embedded a
<Link>
with an API call to react-intl'sformatMessage
within a<FormattedMessage>
Any ideas on how to fix the test framework so that it is injected at all levels? Do I have to use
mount
for this?