Skip to content

Instantly share code, notes, and snippets.

@trieloff
Created February 12, 2019 14:30
Show Gist options
  • Save trieloff/bffcbc4191d1fe523a01ecd3ab4b4654 to your computer and use it in GitHub Desktop.
Save trieloff/bffcbc4191d1fe523a01ecd3ab4b4654 to your computer and use it in GitHub Desktop.
/* 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