Permalink
Browse files

[bug] was still using `constructor.name` in `throw` assertion

  • Loading branch information...
domenic committed Apr 15, 2012
1 parent 44ce348 commit ad3b19fe75e048a339e0268cb9baa90f492b7c22
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/assertion.js
View
@@ -874,7 +874,8 @@ Assertion.prototype.throw = function (constructor, msg) {
new Assertion(obj).is.a('function');
var thrown = false
- , desiredError = null;
+ , desiredError = null
+ , name = null;
if (arguments.length === 0) {
msg = null;
@@ -886,6 +887,10 @@ Assertion.prototype.throw = function (constructor, msg) {
desiredError = constructor;
constructor = null;
msg = null;
+ } else if (typeof constructor === 'function') {
+ name = (new constructor()).name;
+ } else {
+ constructor = null;
}
try {
@@ -900,9 +905,8 @@ Assertion.prototype.throw = function (constructor, msg) {
);
return this;
}
- // if we weren't passed one, check constructor
- if (constructor && 'function' === typeof constructor) {
- var name = (new constructor()).name;
+ // next, check constructor
+ if (constructor) {
this.assert(
err instanceof constructor
, 'expected #{this} to throw ' + name + ' but a ' + err.name + ' was thrown'
@@ -931,7 +935,7 @@ Assertion.prototype.throw = function (constructor, msg) {
}
}
- var expectedThrown = (constructor ? constructor.name : desiredError ? util.inspect(desiredError) : 'an error');
+ var expectedThrown = name ? name : desiredError ? util.inspect(desiredError) : 'an error';
this.assert(
thrown === true

0 comments on commit ad3b19f

Please sign in to comment.