Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add information about Assert behavior and maintenance
Assert is now locked. Userland alternatives should be used. Assert is for testing Node.js itself. Document potentially surprising use of enumerable properties only in deep equality assertions. Ref: #3124 Ref: #3122 PR-URL: #3330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
- Loading branch information
b607366
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be elaborated on? It seems to imply that there's something broken about the
assert
module included with Node.b607366
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many surprises lurking in the Assertion library. For example,
assert.deepEqual(Error('foo'), Error('bar'))
does not throw anAssertionError
. There are many other oddities.b607366
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get a little more specific with a few examples:
deepEqual()
only compares enumerable properties (which explains the surprising result withError
objects mentioned previously)deepEqual()
also ignores attached Symbolsassert.fail()
has a strange method signature that behaves oddly. The first two parameters and the third parameter are mutually exclusive. So, if you want to use the third parameter, which happens to be the typical use case, you have to pass two other parameters for no reason:assert.fail(null, null, 'actual parameter you care about');
There are other things, but none of them are going to be fixed unless they cause problems for Node itself. For more explanation, you can read the discussion in the three issues cited in the commit message:
b607366
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Thank you for the details and references @Trott