-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Labels
Description
π Feature Proposal
I'd really like the ability to extend the toEqual
matcher. In my case, I would like to call .equals
on each of my objects (if it exists), and otherwise resort to the default functionality. I saw this issue (#7351), but it kinda looked like it just stalled...
Motivation
I may have mentioned some of this above, but I want the ability to add extra functionality to the toEqual
matcher, without rewriting the entire thing.
Example
// Test setup somewhere (very rough on implementation)
expect.equalityTester((objectA, objectB) => {
// Do custom .equals checking, otherwise resort to default functionality
})
// In a test
it('correctly checks equality', () => {
const measurement1 = new Measurement(1, 'ft')
const measurement2 = new Measurement(12, 'in')
expect(measurement1).toEqual(measurement2) // Should pass, currently doesn't
})
Pitch
This allows users to extend equality checks as necessary, without large changes
stephenh and stephenpassero