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
@mirague thanks for your help! It was user error on my part that caused the translations to not look up properly 😅
@SamAmiri - what's happening is that you are importing the functions underneath a
mountWithIntl
object. Rather than doing:Try exporting each function individually by name:
This should import properly now: