Last active
February 13, 2019 07:51
-
-
Save trieloff/f5457499ee7e1315245094bb75c51dc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* eslint-env mocha */ | |
const nock = require('nock'); | |
const assert = require('assert'); | |
const { AssertionError } = require('assert'); | |
const { functionundertest } = require('../index'); | |
describe('Testing Errors caused by HTTP Response', () => { | |
let scope; | |
before('Set up a fake HTTP Server', () => { | |
scope = nock('https://api.example.com/') | |
.get('/test') | |
.delay(2000) // delay the response for extra realism | |
.reply(504, 'Gateway Timeout'); | |
}); | |
it('Returns an empty object when the remote server does not respond in time', async () => { | |
const result = await functionundertest(); // this function makes requests to https://api.example.com | |
assert.deepEqualStrict(result, {}); | |
}).timeout(5000); // increase the timeout | |
after('Assert that the HTTP request has been made', () => { | |
scope.done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment