react-scripts 2.1.8 --> 3.0.0 破坏了 redux "connected" 测试?

react-scripts 2.1.8 --> 3.0.0 breaks redux "connected" tests?

遵循找到的测试连接组件的简单指南here我已经对这种格式进行了几个月的测试:

import ConnectedFaultReport, {FaultReport} from [...];
describe('FaultReport (connected) component tests', () => {
  let container = shallow(<ConnectedFaultReport  />);
  it('Should render the Redux connected component', () => {
    expect(container.length).toEqual(1)
  });
})

将 react-scripts 升级到 3.0.0 后,我现在遇到了可怕的事情:

Invariant Violation: Could not find "store" in the context of "Connect(FaultReports)..."

错误。我必须完成所有更简单的连接测试并实施:

import { Provider } from "react-redux";
import configureMockStore from "redux-mock-store";

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

  describe('FaultReport (connected) component tests', () => {
    let container = shallow(
      <Provider store={store}>
        <ConnectedFaultReport />
      </Provider>
    );
    it('Should render the Redux connected component', () => {
      expect(container.length).toEqual(1)
    });
  })

我对 redux-mock-store 没意见,但这是大量的流失和重构。升级后只有我看到这个吗react-scripts

@markerikson:我之前 不是 通过 store 作为道具。实施的升级如下(这次我保存了 ncu 的输出,因为同样的事情发生在一个单独的项目上)。刚注意到 react-redux 也遇到了完整版...

react-redux               ^6.0.1  →   ^7.0.3
react-scripts              2.1.8  →    3.0.0
enzyme-adapter-react-16  ^1.11.2  →  ^1.12.1

我真的很惊讶浅层渲染 <ConnectedFaultReport> 在 React-Redux v6 中完全有效。我们有 several users report that that stopped working entirely。另外,如果您没有将商店作为道具传递将其包装在<Provider>中,那么现有测试应该 失败 - 一个连接的组件总是 需要一个商店,期间。

从 v7 开始,您应该能够再次将商店作为 prop 直接传递(与 v5 和更早版本一样),例如 <ConnectedFaultReport store={store} />