59 lines
1.7 KiB
Diff
59 lines
1.7 KiB
Diff
From bc56c15ecaad15a48de189bf9de80b4a59ae70c1 Mon Sep 17 00:00:00 2001
|
|
From: Gavin Huang <gravof@gmail.com>
|
|
Date: Tue, 25 Sep 2012 13:13:37 +0800
|
|
Subject: [PATCH 06/13] Add 'actual' & 'expected' property to the thrown error
|
|
|
|
---
|
|
expect.js | 18 +++++++++++++-----
|
|
1 file changed, 13 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/expect.js b/expect.js
|
|
index ac14ea8..776fc8c 100644
|
|
--- a/expect.js
|
|
+++ b/expect.js
|
|
@@ -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);
|
|
@@ -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;
|
|
};
|
|
|
|
@@ -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;
|
|
};
|
|
|
|
--
|
|
1.8.2.1
|
|
|