moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

Display custom actual in assertion message #44

Open nwinch opened 8 years ago

nwinch commented 8 years ago

Hey @moll! I noticed in the assert function here:

if (!("actual" in opts)) opts.actual = this.actual
if (!("caller" in opts)) opts.caller = assert.caller

var msg = stringify(this.actual) + " must " + (this.negative ? "not " : "")

That this.actual is stringified, though could that be stringify(opts.actual) instead? As this.actual is assigned to opts.actual a couple of lines above anyway if it doesn't already exist.

This would help me pass a more pleasant looking actual for the assertion error message, which I'm doing over at must-jsx.

moll commented 8 years ago

Hey! Sure, customizing what gets stringified makes sense. I see there's Must.prototype.throw that uses the actual parameter for assigning to the error object but still expecting the original actual (the function that threw an exception) to be stringified. Once I figure out how these two cases can co-exist, I'll make the change ;)