用酶测试react-intl组分

Dea*_*ish 7 unit-testing reactjs enzyme react-intl

我已经查看了react-intl的建议,但它没有留下任何关于酶的明确文档.

这就是我试图编写测试的方法.

import {IntlProvider} from 'react-intl';

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

但我一直在收到错误

不变违规:[React Intl]找不到必需的intl对象.需要存在于组件祖先中.

我查看了他们的回购,他们似乎已经使它与'react-addons-test-utils'一起使用了.

难道我做错了什么?

Mir*_*age 4

我已经发布了类似问题的答案:

将react-intl对象注入已安装的Enzyme组件中进行测试

您将能够import { shallowWithIntl } from 'intl-helper'然后使用shallowWithIntl()而不是 Enzyme's shallow()