making a request in my action. Pulling from api that need to return values from mock redux store. I have it start that request when redux mock store dispatch action, but i can't seem the values correctly when store.getActions().
I getting error store.getActions()
is returning the state empty from the mock store .
For example:
simpleActions.js
export const fetchTodos = () => {
return async (dispatch) => {
const response = await axios.get('https://myweb.com/example.json');
dispatch({ type: types.FETCH_TODOS_REQUEST , payload: response.data });
}
}
simpleAction.test.js
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
describe('async actions', () => {
afterEach(() => {
fetchMock.restore()
})
it('creates FETCH_TODOS_SUCCESS when fetching todos has been done', () => {
fetchMock.getOnce('/todos', {
body: { todos: ['do something'] },
headers: { 'content-type': 'application/json' }
})
const expectedActions = [
{ type: types.FETCH_TODOS_REQUEST },
{ type: types.FETCH_TODOS_SUCCESS, body: { todos: ['do something'] } }
]
const store = mockStore({ todos: [] })
const dispatchStored = store.dispatch(actions.fetchTodos());
return dispatchStored.then(() => {
**const values = store.getActions();**
This values is returning the state empty array from the mock store.
expect(store.getActions()).toEqual(expectedActions)
})
})
})
How to call or mock async/await function that need to return values instead of the state empty array from the mock store. Any helps would be appreciated.