Last active
July 30, 2018 17:13
-
-
Save FabricioFFC/7a0fe7b257f29b4908c4634ad6034f2e to your computer and use it in GitHub Desktop.
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
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