Last active
October 2, 2017 11:56
-
-
Save edmulraney/a0e439a291261076a4967d24dffa8e8a 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 { | |
| POST_USER_REQUESTED, | |
| POST_USER_SUCCEEDED, | |
| POST_USER_FAILED, | |
| } from './action-types' | |
| const API_SERVICE_PATH = './api-service' | |
| describe('postUser', () => { | |
| beforeEach(() => { | |
| jest.resetModules() | |
| }) | |
| it('dispatches failure actions', () => { | |
| const userPayload = { userId: 'MOCK_ID', name: 'John' } | |
| const response = 'MOCK_ERROR_RESPONSE' | |
| const store = createThunkStore() | |
| jest.doMock(API_SERVICE_PATH, () => ({ | |
| post: () => Promise.reject(response), | |
| })) | |
| const { postUser } = require('./actions') // eslint-disable-line | |
| 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 store = createThunkStore() | |
| jest.doMock(API_SERVICE_PATH, () => ({ | |
| post: () => Promise.resolve(response), | |
| })) | |
| const { postUser } = require('./actions') // eslint-disable-line | |
| 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