Skip to content

Instantly share code, notes, and snippets.

@trieloff
Created February 13, 2019 10:00
Show Gist options
  • Save trieloff/8236eadc09ffe3495b704205f66164e4 to your computer and use it in GitHub Desktop.
Save trieloff/8236eadc09ffe3495b704205f66164e4 to your computer and use it in GitHub Desktop.
/* eslint-env mocha */
const sinon = require('sinon');
const proxyquire = require('proxyquire');
const assert = require('assert');
const { functionundertest } = require('../index');
describe('Testing Errors caused by HTTP Response', () => {
let functionundertest;
let somefunction;
before('Set up a fake HTTP Server', () => {
somefunction = sinon.fake.throws(new Error('Some Error')); // this is the error that
// somefunction would normally
// throw, that cannot be
// reliably reporoduced
functionundertest = proxyquire('../index', {
somemodule: {
somefunction
}
});
});
it('Returns an empty object when the nested function throws an error', async () => {
const result = await functionundertest(); // this function calls somemodule.somefunction
assert.deepEqualStrict(result, {});
});
after('Assert that somefunction in somemodule has been called', () => {
assert.ok(somefunction.calledOnce);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment