Nested components testing with Enzyme inside of React & Redux

后端 未结 6 1105
甜味超标
甜味超标 2020-12-24 05:55

I have a component SampleComponent that mounts another \"connected component\" (i.e. container). When I try to test SampleComponent by

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 06:39

    There is also the option to use redux-mock-store.

    A mock store for testing Redux async action creators and middleware. The mock store will create an array of dispatched actions which serve as an action log for tests.

    The mock store provides the necessary methods on the store object which are required for Redux. You can specify optional middlewares and your app specific initial state.

    import configureStore from 'redux-mock-store'
    
    const middlewares = []
    const mockStore = configureStore(middlewares)
    
    const initialState = {}
    const store = mockStore(initialState)
    
    const wrapper = mount()
    

提交回复
热议问题