2016-04-26 15 views
5

私は提案のために反応intlを調べたが、enzymeの明示的な文書は残さない。酵素と反応するintl成分を調べる

これは私がテストを書く方法です。

import {IntlProvider} from 'react-intl'; 

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

しかし、私は不変違反エラーに

を得続ける:[国際を反応させるのが]必要なintlオブジェクトが見つかりませんでした。コンポーネントの祖先に存在する必要があります。

私は彼らのレポを調べました。彼らはmade it workを 'react-addons-test-utils'としているようです。

何か間違っていますか?

答えて

0

私の代わりに

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

を使用して作業それを得ました。

+0

これは、「浅い」インスタンス化の良いアプローチです。 Enzymeの 'mount'メソッドを使用している場合、これは機能しません。 – Mirage

+0

enzyme-react-intlパッケージを試しましたか? – JoeTidee

関連する問題