Skip to content

Commit

Permalink
return error on throw method to chain on error properties, possibly d…
Browse files Browse the repository at this point in the history
…ifferent from message
  • Loading branch information
Virginie BARDALES committed Dec 19, 2013
1 parent 0e560c6 commit c32ae3e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ module.exports = function (chai, _) {
* @param {String|RegExp} expected error message
* @param {String} message _optional_
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @returns error for chaining (null if no error)
* @api public
*/

Expand Down Expand Up @@ -1043,6 +1044,7 @@ module.exports = function (chai, _) {
, (desiredError instanceof Error ? desiredError.toString() : desiredError)
, (err instanceof Error ? err.toString() : err)
);
flag(this, 'object', err);

return this;
}
Expand All @@ -1056,7 +1058,10 @@ module.exports = function (chai, _) {
, (err instanceof Error ? err.toString() : err)
);

if (!errMsg) return this;
if (!errMsg) {
flag(this, 'object', err);
return this;
}
}
// next, check message
var message = 'object' === _.type(err) && "message" in err
Expand All @@ -1071,6 +1076,7 @@ module.exports = function (chai, _) {
, errMsg
, message
);
flag(this, 'object', err);

return this;
} else if ((message != null) && errMsg && 'string' === typeof errMsg) {
Expand All @@ -1081,6 +1087,7 @@ module.exports = function (chai, _) {
, errMsg
, message
);
flag(this, 'object', err);

return this;
} else {
Expand All @@ -1107,6 +1114,7 @@ module.exports = function (chai, _) {
, (desiredError instanceof Error ? desiredError.toString() : desiredError)
, (thrownError instanceof Error ? thrownError.toString() : thrownError)
);
flag(this, 'object', null);
};

Assertion.addMethod('throw', assertThrows);
Expand Down

0 comments on commit c32ae3e

Please sign in to comment.