Last active
October 2, 2017 11:56
-
-
Save edmulraney/a0e439a291261076a4967d24dffa8e8a to your computer and use it in GitHub Desktop.
Revisions
-
edmulraney renamed this gist
Oct 2, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
edmulraney created this gist
Oct 2, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ 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) }) }) })