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;
但沒有任何反應。