Skip to content

Commit

Permalink
Added formatting for Error objects
Browse files Browse the repository at this point in the history
Printing an error object from node.js generates an unhelpful `{}` response.

~~~
var e = new Error("Something went bad");
expect(e).to.be(null); // Prints Error: expected {} to equal null
~~~

Passing the response through toString gives a nicer result:

~~~
Prints Error: expected [Error: Something went wrong] to equal null
~~~
  • Loading branch information
mikeando committed Apr 10, 2013
1 parent 5a1e44c commit 85b59d3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion expect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

(function (global, module) {

if ('undefined' == typeof module) {
Expand Down Expand Up @@ -619,6 +618,11 @@
if (isDate(value) && $keys.length === 0) {
return stylize(value.toUTCString(), 'date');
}

// Error objects can be shortcutted
if (value instanceof Error) {
return stylize("["+value.toString()+"]", 'Error');
}

var base, type, braces;
// Determine the object type
Expand Down

0 comments on commit 85b59d3

Please sign in to comment.