Created
October 2, 2017 17:05
-
-
Save edmulraney/7171420365f8cdd1849b96cf0089de62 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 './ceate-thunk-store' | |
| import { postUser } from './actions' | |
| import { | |
| POST_USER_REQUESTED, | |
| POST_USER_SUCCEEDED, | |
| POST_USER_FAILED, | |
| } from './action-types' | |
| const API_SERVICE_PATH = './api-service' | |
| describe('postUser', () => { | |
| let actionsInjector | |
| beforeEach(() => { | |
| actionsInjector = require('inject-loader!./actions') // eslint-disable-line | |
| }) | |
| it('dispatches failure actions', () => { | |
| const userPayload = { accountId: 'MOCK_ID' } | |
| const response = 'MOCK_ERROR_RESPONSE' | |
| const store = createThunkStore() | |
| actionsInjector({ | |
| API_SERVICE_PATH: { | |
| post: () => Promise.reject(response), | |
| }, | |
| }) | |
| return store.dispatch(postUser(userPayload)).then(() => { | |
| const actions = store.getActions() | |
| const expectedFailurePayload = { | |
| errorResponse: response, | |
| meta: { | |
| accountId: userPayload.accountId, | |
| }, | |
| } | |
| const expectedActions = [ | |
| { type: POST_USER_REQUESTED, payload: userPayload }, | |
| { type: POST_USER_FAILED, payload: expectedFailurePayload }, | |
| ] | |
| expect(actions).toEqual(expectedActions) | |
| }) | |
| }) | |
| it('dispatches success actions', () => { | |
| const userPayload = { accountId: 'MOCK_ID' } | |
| const response = 'MOCK_SUCCESS_RESPONSE' | |
| const store = createThunkStore() | |
| actionsInjector({ | |
| API_SERVICE_PATH: { | |
| post: () => Promise.resolve(response), | |
| }, | |
| }) | |
| 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