Testing Reactive Enzyme Components

I reviewed the interactive guidelines, but leaves no explicit documentation for the enzyme .

This is how I tried to write my tests.

import {IntlProvider} from 'react-intl'; const intlProvider = new IntlProvider({locale: 'en'}, {}); const intl = intlProvider.getChildContext(); const customMessage = shallow(<CustomMessage />, { options: { context: intl } }); 

But I keep getting the error

Invariant violation: [React Intl] Could not find the required intl object. must exist in the pedigree of the component.

I looked through their repo and they seem to have done its job using 'react-addons-test-utils'.

Am I doing something wrong?

+5
source share
2 answers

I sent an answer to a similar question:

Injection of the response object into the installed Enzyme components for testing

You could import { shallowWithIntl } from 'intl-helper' and then use shallowWithIntl() instead of Enzyme shallow() .

+2
source

I started working using

 const customMessage = shallow(<CustomMessage />, { context: intl }); 

instead.

0
source

Source: https://habr.com/ru/post/1247949/


All Articles