Last active
November 20, 2017 22:30
-
-
Save paulsturgess/adcc72f752fa5381bc0ca22c0be91c32 to your computer and use it in GitHub Desktop.
Test a redux-thunk action
This file contains 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
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