Last active
October 2, 2017 15:30
-
-
Save edmulraney/6b5c489440a58fb1c71ac45d24d1dc6c 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 createThunkStore from './create-thunk-store' | |
| import { postUser } from './actions' | |
| import { | |
| POST_USER_REQUESTED, | |
| POST_USER_SUCCEEDED, | |
| POST_USER_FAILED, | |
| } from './action-types' | |
| describe('postUser', () => { | |
| describe('dispatches correct actions', () => { | |
| it('dispatches failure actions', () => { | |
| const userPayload = { userId: 'MOCK_ID', name: 'John' } | |
| const response = 'MOCK_ERROR_RESPONSE' | |
| const api = { post: () => Promise.reject(response) } | |
| const store = createThunkStore({ api }) | |
| return store.dispatch(postUser(userPayload)).then(() => { | |
| const actions = store.getActions() | |
| const expectedFailResponse = { userId: userPayload.userId, errorResponse: response } | |
| const expectedActions = [ | |
| { type: POST_USER_REQUESTED, payload: userPayload }, | |
| { type: POST_USER_FAILED, payload: expectedFailResponse }, | |
| ] | |
| expect(actions).toEqual(expectedActions) | |
| }) | |
| }) | |
| it('dispatches success actions', () => { | |
| const userPayload = { userId: 'MOCK_ID', name: 'John' } | |
| const response = 'MOCK_SUCCESS_RESPONSE' | |
| const api = { post: () => Promise.resolve(response) } | |
| const store = createThunkStore({ api }) | |
| return store.dispatch(postUser(userPayload)).then(() => { | |
| const actions = store.getActions() | |
| const expectedActions = [ | |
| { type: POST_USER_REQUESTED, payload: userPayload }, | |
| { type: POST_USER_SUCCEEDED, payload: response }, | |
| ] | |
| expect(actions).toEqual(expectedActions) | |
| }) | |
| }) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment