我正在努力对componentWillLoad()生命周期中的商店进行单元测试。
我已尝试遵循以下指南:https://github.com/dmitry-zaets/redux-mock-store
component.tsx
@Prop({ context: "store" }) store: Store;
componentWillLoad() {
this.store.mapDispatchToProps(this, { updateStep });
}
spec.ts
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
const mapDispatchToProps = () => ({ type: updateStep});
it('should test componentWillLoad', () => {
const initialState = {};
const store = mockStore(initialState);
store.dispatch(mapDispatchToProps());
const actions = store.updateStep();
const expectedPayload = { type: updateStep};
expect(actions).toEqual([expectedPayload]);
});
我收到以下atm错误:TypeError:mockStore不是函数