Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Last active November 20, 2017 22:30
Show Gist options
  • Save paulsturgess/adcc72f752fa5381bc0ca22c0be91c32 to your computer and use it in GitHub Desktop.
Save paulsturgess/adcc72f752fa5381bc0ca22c0be91c32 to your computer and use it in GitHub Desktop.
Test a redux-thunk action
describe('saveResource', () => {
let resource = { id: 5, name: 'foo' };
describe('when the response is a 200', () => {
let dispatch = jasmine.createSpy('dispatch');
beforeEach(() => {
spyOn(Service, 'post').and.callFake(function(url, payload, callback) {
callback(200, {foo: 'bar'})
})
});
it('posts the data to the Service class and dispatches RESOURCE_SUCCESSFULLY_SAVED', () => {
Actions.saveResource(resource)(dispatch)
expect(Service.post).toHaveBeenCalledWith(
'/your/path',
resource,
jasmine.any(Function)
)
expect(dispatch).toHaveBeenCalledWith(
{type: 'RESOURCE_SUCCESSFULLY_SAVED', data: { foo: 'bar' }}
)
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment