tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 194 forks source link

Custom messages on the error object #133

Closed nbrownus closed 11 years ago

nbrownus commented 11 years ago

The main goal of this pull request is to add the custom message to the error object so that it can be referenced without doing string manipulation on the error message itself (splitting at the pipe).

I also did some doc fixing and whatnot

btd commented 11 years ago

err.description not standart property. It is not used neither Error nor AssertionError. So what is idea to add it to error?

nbrownus commented 11 years ago

The original code appends the custom message to the end of the error message, adding a pipe. If an error is thrown and it contains a custom message there is no elegant way to get just that message.

Mocha, for example, does not print the error message if a diff can be shown. This leads to the custom message never being printed. If there was a reliable way to get the custom message Mocha could print this along with the diff, which is what I have done in a fork.

btd commented 11 years ago

So you mean that mocha can use err.description?

nbrownus commented 11 years ago

Or any other project that consumes errors thrown by should.js

btd commented 11 years ago

Hm, it does not look that mocha use this field. In any case i am ok with this PR, i will test and merge tomorrow to v2 (for 2.0.0). 2.0.0 probably will be available at the end of week or monday.

nbrownus commented 11 years ago

Mocha does not currently, if/when this PR get's merged I will do a PR to Mocha to use the field.

Appreciate the help!

btd commented 11 years ago

I merged this pr, but release date moved to future in 2 weeks i think.