🚀 Feature: Give some control on how diffs are rendered #5088
Open
Description
opened on Jan 24, 2024
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
faq
label, 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
Activity