使用 Provider 但仍然看到错误 Invariant Violation: Could not find "store" in the context of "Connect

Using a Provider but still seeing error Invariant Violation: Could not find "store" in the context of "Connect

我看过几个答案,但都建议将主要组件包装在 Provider 中。

我已经这样做了,但错误仍然存​​在。

这是我的 App.js 组件

const App = ({ store }) =>
  <Provider store={store}>
    <div className="App">
      <Users/>
    </div>
  </Provider>

我正在做一个非常简单的测试。第一次使用酵素,

import React from 'react'
import Adapter from 'enzyme-adapter-react-16'
import Users from './'
import { shallow, configure } from 'enzyme'

configure({adapter: new Adapter()});

describe('First React component test with Enzyme', () => {
  it('renders without crashing', () => {
    shallow(<Users />);
  });
});

错误是:

不变违规:无法在 "Connect(Users)" 的上下文中找到 "store"。要么将根组件包装在 Provider 中,要么将自定义 React 上下文提供程序传递给 Provider,并将相应的 React 上下文使用者传递给连接选项中的 Connect(Users)。

可能的解决方案如下:

import React from "react";
import { shallow } from "enzyme";
import { Provider } from "react-redux";
import configureMockStore from "redux-mock-store";
import Userfrom "../User";

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

describe('First React component test with Enzyme', () => {
  it('renders without crashing', () => {
    shallow(
     <Provider store={store}>
      <User/>
     </Provider>
    );
  });
});