caolan/nodeunit — pull request #147 by allanmboyd (2012-01-07 22:47:52+00:00)
Title: update to utils.betterErrors to better handle undefined expected and actual

Hi,

This is a minor update to utils.betterErrors that is not intended to incorporate any changes that could break anyone (e.g. no API changes, no change in return type).

The goal is to make utils.betterErrors play better with assertion errors that do not contain values for expected and actual. Prior to this change when there are no expected/actual values the message that is produced as the first line of the error stack is "AssertionError: undefined undefined undefined" - this happens for example with the assert.throws() assertion.

(I have to admit that I am unclear on the reason for the usage Object.getOwnPropertyDescriptor as it is this that is causing the problem. It would be possible to make the fix and still keep the usage of Object.getOwnPropertyDescriptor but since all the tests still pass hopefully I have not broken anything by removing it and replacing with a simple basic alternative - I look forward to being educated otherwise if this is not the case!)

As it happens this change also helps with richer assertion libraries such as should.js, which have many assertions that do not include expected or actual and is really my main objective - i.e. to improve nodeunit integration with alternative assertion libraries. To illustrate this I have included should.js as a devdependency in package.json and use it in the provided test case. If that dependency proves to be an obstacle then I am happy to remove it and re-submit.

thanks,
Allan