使用Jest在带有Redux的Stencil中对store.mapDispatchToProps进行单元测试

时间:2019-05-23 10:38:24

标签: redux jestjs stenciljs

我正在努力对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不是函数

0 个答案:

没有答案