2016-04-26 136 views
5

我已經查看了react-intl的建議,但沒有留下任何明確的文檔enzyme用酶測試react-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

您是否嘗試過酶反應-intl包裝? – JoeTidee