Skip to content

Commit

Permalink
Fix #317
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Jul 1, 2019
1 parent aecedb0 commit b930b49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Expand Up @@ -592,6 +592,12 @@ exports.assert = function (condition, ...args) {
return;
}

if (args.length === 1 &&
args[0] instanceof Error) {

throw args[0];
}

throw new exports.Error(args);
};

Expand Down
9 changes: 4 additions & 5 deletions test/index.js
Expand Up @@ -179,7 +179,7 @@ describe('clone()', () => {
it('shallow clones map', () => {

const map = new Map();
map.set('a', { x : 1 });
map.set('a', { x: 1 });
map.set(map, map);

const clone = Hoek.clone(map, { shallow: true });
Expand Down Expand Up @@ -2487,10 +2487,9 @@ describe('assert()', () => {

it('throws an Error when using assert in a test with error object message', () => {

expect(() => {

Hoek.assert(false, new Error('This is spinal tap'));
}).to.throw('This is spinal tap');
const err = new Error('This is spinal tap');
const got = expect(() => Hoek.assert(false, err)).to.throw('This is spinal tap');
expect(got).to.shallow.equal(err);
});

it('throws the same Error that is passed to it if there is only one error passed', () => {
Expand Down

0 comments on commit b930b49

Please sign in to comment.