-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
status: in discussionLet's talk about it!Let's talk about it!type: featureenhancement proposalenhancement proposal
Description
Feature Request Checklist
- I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
- I have searched for related issues and issues with the
faqlabel, but none matched my issue. - I want to provide a PR to resolve this
Overview
I use some custom comparators with chai which allows me to do things such as:
assert.deepEqual({a: 1}, {a: new Interval(0, 10)});
Unfortuantly, when the assertion fails, I don't have any control on how the diff should be rendered, and the diff will expose the internal structure of the Interval class with is not super helpful. I would like to have some control on how the diff is rendered.
Suggested Solution
I thought of a simple solution which works rather well for simple use case, which would be to call toJSON (if available) before object canonicalization (and this way my Interval class could decide a bit how it want to be rendered for the diff).
It feels a fair think to do, and it's already done in the specific case of Buffer class https://github.com/mochajs/mocha/blob/master/lib/utils.js#L218
Alternatives
- Defining a special function "toMochaDiff" (of something similar) to avoid colliding with other use of toJSON
- Give user full control over diff rendering by adding hooks to stringifyDiffObjs and generateDiff in base reporter
Additional Info
No response
Metadata
Metadata
Assignees
Labels
status: in discussionLet's talk about it!Let's talk about it!type: featureenhancement proposalenhancement proposal
Type
Projects
Status
No status