Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save edmulraney/7171420365f8cdd1849b96cf0089de62 to your computer and use it in GitHub Desktop.

Select an option

Save edmulraney/7171420365f8cdd1849b96cf0089de62 to your computer and use it in GitHub Desktop.
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