0

我正在尝试测试我的组件,但由于商店我有一个错误。

import React from 'react';
import { shallow, simulate } from 'enzyme';
import configureStore from 'redux-mock-store';
import { Provider } from "react-redux";

import DropzoneComponent from '../components/DropzoneComponent';

const mockStore = configureStore();
const store = mockStore({});


describe('Dropzone component live test', () => {
    it('renders the component', () => {
      const wrapper = shallow(
        <Provider store = {store}>
          <DropzoneComponent />
        </Provider>).dive();
      expect(wrapper.exists()).to.equal(true)
    });
});

错误是:

不变违规:在“Connect(withRouter(DropzoneComponent))”的上下文或道具中找不到“store”。要么将根组件包装在 a 中,要么将“store”作为道具显式传递给“Connect(withRouter(DropzoneComponent))”。

4

1 回答 1

1

您的组件被包裹着,withRoter您需要在浅层渲染时将其公开,WrappedComponent如下所示:

describe('Dropzone component live test', () => {
it('renders the component', () => {
  const wrapper = shallow(
    <Provider store = {store}>
      <DropzoneComponent.WrappedComponent />
    </Provider>).dive();
  expect(wrapper.exists()).to.equal(true)
 });
});

让我知道问题是否仍然存在

于 2018-08-24T21:18:01.123 回答