Skip to content

Instantly share code, notes, and snippets.

@lotif
Last active June 17, 2017 02:05
Show Gist options
  • Save lotif/9c149f64725cb67fbeb596c4495a07b4 to your computer and use it in GitHub Desktop.
Save lotif/9c149f64725cb67fbeb596c4495a07b4 to your computer and use it in GitHub Desktop.
testing http calls
// to mock a whole imported dependency, do this
jest.mock('my-http-client');
import http from 'my-http-client';
// ...
it('should change the text on click', () => {
http.get.mockImplementation({ body: 'the-return-of-my-get-request' });
const sut = mount(
<Provider store={store}>
<MyComponent />
</Provider>
);
sut.find('div').simulate('click');
expect(sut.find('div').prop('children')).toEqual('the-return-of-my-get-request');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment