Created
February 12, 2019 14:30
-
-
Save trieloff/bffcbc4191d1fe523a01ecd3ab4b4654 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 assert = require('assert'); | |
const { AssertionError } = require('assert'); | |
const { functionundertest } = require('../index'); | |
describe('Testing Error States', () => { | |
it('Throws an error when called with missing arguments', () => { | |
try { | |
functionundertest(); // this should fail | |
assert.fail('expected exception not thrown'); // this throws an AssertionError | |
} catch (e) { // this catches all errors, those thrown by the function under test | |
// and those thrown by assert.fail | |
if (e instanceof AssertionError) { | |
// bubble up the assertion error | |
throw e; | |
} | |
assert.equal(e.message, 'Invalid Arguments'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment