Created
February 13, 2019 10:00
-
-
Save trieloff/8236eadc09ffe3495b704205f66164e4 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 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