0
我一直在努力,因为当我运行测试,我有这个错误嘲讽React-Intl library与Jest:手册模拟阵营,国际与玩笑有快照测试
Invariant Violation: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
这个库的documentation说,我们有中创建一个名为__Mocks__
根项目文件夹,然后添加此文件:
// ./__mocks__/react-intl.js
import React from 'react';
const Intl = require.requireActual('react-intl');
// Here goes intl context injected into component, feel free to extend
const intl = {
formatMessage: ({defaultMessage}) => defaultMessage
};
Intl.injectIntl = (Node) => (props) => <Node {...props} intl={intl}/>;
module.exports = Intl;
但没有任何反应。