Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Created October 31, 2018 16:48
Show Gist options
  • Save tfiechowski/5c2350f0f4115bc55233cd157c3d4ad0 to your computer and use it in GitHub Desktop.
Save tfiechowski/5c2350f0f4115bc55233cd157c3d4ad0 to your computer and use it in GitHub Desktop.
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