Skip to content

Instantly share code, notes, and snippets.

@trieloff
Last active February 13, 2019 07:51
Show Gist options
  • Save trieloff/f5457499ee7e1315245094bb75c51dc2 to your computer and use it in GitHub Desktop.
Save trieloff/f5457499ee7e1315245094bb75c51dc2 to your computer and use it in GitHub Desktop.
/* 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