Skip to content

Commit

Permalink
Add assert.throws
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Dec 3, 2014
1 parent ea3bc4d commit 28f5c02
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/helpers/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ assert.notSameValue = function (actual, unexpected, message) {
}
$ERROR(message);
};

assert.throws = function (expectedErrorConstructor, func, message) {
try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
$ERROR('Thrown value was not an object!');
}
if (thrown.constructor !== expectedErrorConstructor) {
$ERROR('Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name);
}
return;
}

$ERROR('Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all');
};

0 comments on commit 28f5c02

Please sign in to comment.