Skip to content

Instantly share code, notes, and snippets.

@LarryKarani
Created April 9, 2020 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarryKarani/2536a85dcdf473b7d7d0bd88cbd7aa82 to your computer and use it in GitHub Desktop.
Save LarryKarani/2536a85dcdf473b7d7d0bd88cbd7aa82 to your computer and use it in GitHub Desktop.
describe('post Todos actions', () => {
beforeEach(() => {
store.clearActions();
});
it('dispatches POST_TODO_SUCCESS after a successfull API requets', () => {
mock.onPost('api/todos').reply(201, { response: { item: 'item1' } })
store.dispatch(actions.getTodos()).then(() => {
let expectedActions = [
{ type: 'API_REQUEST' },
{ type: 'POST_TODOS_SUCCESS', payload: { item: 'item1' } }
]
expect(store.getActions()).toEqual(expectedActions)
});
});
it('dispatches POST_TODO_FAILURE after a FAILED API requets', () => {
mock.onPost('api/todos').reply(400, { error: { message: 'error message' } });
store.dispatch(actions.getTodos()).then(() => {
let expectedActions = [
{ type: 'API_REQUEST' },
{
type: 'POST_TODOS_FAIL',
payload: { error: { message: 'error message' } }
}
]
expect(store.getActions()).toEqual(expectedActions)
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment