按照此处找到的测试连接组件的简单指南,我已经通过这种格式的测试几个月了:
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