jeudi 11 août 2016

redux-mock-store store's state is not updating after dispatching actions

I have a logger middleware that shows actions about to be dispatched and next state.

I am writing tests for my action and in the mock store I am dispatching the actions. These successfully dispatch however the mock store state is not being updated (as shown by the aforementioned logger).

please note I am using redux-mock-store.

//authActionTest.js

it('creates LOGIN_SUCCESS when successful login has occured', ()=>{

//array of expected actions to be dispatched.
const expectedActions = [
  { type: constants.LOGIN_REQUEST },
  { type: 'LOGIN_SUCCESS',
            payload: {
                uid: '123abc',
                role: 'clinician'
    }}
]
const store = mockStore({ auth : {} })

return store.dispatch(actions.loginUser('abc@123.com', 'password123'))
expect(store.getActions()).toEqual(expectedActions)
})

The logger shows the following:

//logger
dispatching({ type: 'LOGIN_REQUEST })
next state { auth: {} }
dispatching({ type: 'LOGIN_SUCCESS',
   payload: { uid: 123,
              role: 'clinician'
          })
next state { auth: {} }

Aucun commentaire:

Enregistrer un commentaire