Created
October 31, 2018 16:48
-
-
Save tfiechowski/5c2350f0f4115bc55233cd157c3d4ad0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configureMockStore from 'redux-mock-store' | |
import thunk from 'redux-thunk' | |
import * as actions from '../../actions/TodoActions' | |
import * as types from '../../constants/ActionTypes' | |
import fetchMock from 'fetch-mock' | |
import expect from 'expect' // You can use any testing library | |
| |
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: [] }) | |
return store.dispatch(actions.fetchTodos()).then(() => { | |
// return of async actions | |
expect(store.getActions()).toEqual(expectedActions) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment