Skip to content

Instantly share code, notes, and snippets.

@FabricioFFC
Last active July 30, 2018 17:13
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 FabricioFFC/7a0fe7b257f29b4908c4634ad6034f2e to your computer and use it in GitHub Desktop.
Save FabricioFFC/7a0fe7b257f29b4908c4634ad6034f2e to your computer and use it in GitHub Desktop.
import nock from 'nock';
import httpRequest from '../../../src/services/httpRequest';
import teamsListExpectedData from '../../fixtures/httpResponses/teamsList'
describe('httpRequest', () => {
describe('.get', () => {
it('returns the data from the http endpoint', async () => {
// given
nock('http://mock-api.com.br')
.get('/teams')
.reply(200, teamsListExpectedData);
// when
const data = await httpRequest.get('http://mock-api.com.br/teams');
// then
expect(data).toEqual(teamsListExpectedData);
});
it('returns an error when the http endpoint returns 500', async () => {
// given
const expectedError = { message: 'some error occurred' };
const expectedHttpStatus = 500;
nock('http://mock-api.com.br')
.get('/teams')
.reply(expectedHttpStatus, expectedError);
// when
const data = await httpRequest.get('http://mock-api.com.br/teams');
// then
expect(data).toEqual({status: expectedHttpStatus, error: expectedError});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment