使用 Jest 进行测试,我刚刚下载并安装了带有蒲公英模板的 React Boilerplate 并配置了 Jest,运行时npm test
出现了以下问题:
这是测试它指向的错误:
import React from 'react';
import { shallow, mount } from 'enzyme';
import { FormattedMessage, defineMessages } from 'react-intl';
import { Provider } from 'react-redux';
import { browserHistory } from 'react-router-dom';
import ConnectedLanguageProvider, { LanguageProvider } from '../index';
// import configureStore from '../../../configureStore';
import configureStore from '../../../redux/configureStore';
import { translationMessages } from '../../../i18n';
const messages = defineMessages({
someMessage: {
id: 'some.id',
defaultMessage: 'This is some default message',
en: 'This is some en message',
},
});
describe('<LanguageProvider />', () => {
it('should render its children', () => {
const children = <h1>Test</h1>;
const renderedComponent = shallow(
<LanguageProvider messages={messages} locale="en">
{children}
</LanguageProvider>,
);
expect(renderedComponent.contains(children)).toBe(true);
});
});
describe('<ConnectedLanguageProvider />', () => {
let store;
beforeAll(() => {
store = configureStore({}, browserHistory);
});
it('should render the default language messages', () => {
const renderedComponent = mount(
<Provider store={store}>
<ConnectedLanguageProvider messages={translationMessages}>
<FormattedMessage {...messages.someMessage} />
</ConnectedLanguageProvider>
</Provider>,
);
expect(
renderedComponent.contains(
<FormattedMessage {...messages.someMessage} />,
),
).toBe(true);
});
});
这是包含在其中的默认测试。我进入了文档,并且我一直在搜索解决方案,但我一直找不到。我该如何解决这个问题?