Skip to content

Commit

Permalink
Add 'actual' & 'expected' property to the thrown error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Huang committed Sep 25, 2012
1 parent a17b211 commit bc56c15
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@
* @api private
*/

Assertion.prototype.assert = function (truth, msg, error) {
Assertion.prototype.assert = function (truth, msg, error, expected) {
var msg = this.flags.not ? error : msg
, ok = this.flags.not ? !truth : truth;
, ok = this.flags.not ? !truth : truth
, err;

if (!ok) {
throw new Error(msg.call(this));
err = new Error(msg.call(this));
if (arguments.length > 3) {
err.actual = this.obj
err.expected = expected
}
throw err
}

this.and = new Assertion(this.obj);
Expand Down Expand Up @@ -200,7 +206,8 @@
this.assert(
obj === this.obj
, function(){ return 'expected ' + i(this.obj) + ' to equal ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to not equal ' + i(obj) });
, function(){ return 'expected ' + i(this.obj) + ' to not equal ' + i(obj) }
, obj);
return this;
};

Expand All @@ -214,7 +221,8 @@
this.assert(
expect.eql(obj, this.obj)
, function(){ return 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) });
, function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) }
, obj);
return this;
};

Expand Down

0 comments on commit bc56c15

Please sign in to comment.