Rishabh Mishra
Rishabh Mishra

Reputation: 508

testing redux thunk async actions give undefined instead of promise

I have a function which creates actions

export function dispatchAction (type, payload) {
 return dispatch => {
  dispatch({type: type, payload: payload})
 }
}

I am writing test for it

import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as actions from './actions
const mockStore = configureMockStore([thunk])
const store = mockStore({})

describe('dispatch action', () => {
 it('should return action based on type and payload', () => {
  const type = 'TEST'
  const payload = 'payload'
  return store.dispatch(actions.dispatchAction(type, payload)).then(() 
   => {
    expect(store.getActions())
     .toEqual({type, payload})
    })
   })
 })

but I am getting the error that Cannot read property 'then' of undefined.

Upvotes: 0

Views: 188

Answers (1)

Robert Farley
Robert Farley

Reputation: 2456

As per the docs:

Any return value from the inner function will be available as the return value of dispatch itself.

You don't return anything in your dispatchAction, hence the error message. If you want a Promise, then you have to return a Promise.

Upvotes: 1

Related Questions