Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Feature]: Allow extending functionality of toEqualΒ #12880

@stephenpassero

Description

@stephenpassero

πŸš€ 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions