There are two problems with testing components that use React Intl with Enzyme and Jest:
injectIntl higher-order component will break shallow rendering because it will render a wrapper component instead of your component.
intl prop will make snapshot testing useless because each snapshot will contain all your messages.
The solution is based on React Intl’s wiki:
- Add two new helper functions to your Jest setup file (setupFiles):
- Export your component with and without
- Write test cases almost as usual, using the
P. S. You may also enjoy my more generic article on testing React components with Jest and Enzyme and Jest cheat sheet.