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

Skip to content

Adding asymmetric matcher expect.closeToΒ #12242

@Biki-das

Description

@Biki-das

πŸš€ Feature Proposal

There is a matcher toBeCloseTo that's super useful to assert floats. But when these floats are inside objects or arrays we can't use it directly. Therefore it would be useful to have an asymmetric matcher so that we can use toEqual with it, eg:

expect(value).toEqual([
{ start: expect.closeTo(5.3), end: expect.closeTo(5.8) }
]);

It makes sense to be included in Jest core because of the existing matcher toBeCloseTo, that would be more consistent.

Thanks!.

Motivation

t would be useful to have an asymmetric matcher so that we can use toEqual with it, eg:

expect(value).toEqual([
{ start: expect.closeTo(5.3), end: expect.closeTo(5.8) }
]);

Example

it used the same algorith in toBeCloseTo

Pitch

toBeCloseTo is super useful to assert floats. but when these floats are inside of any array or object, we can access it directly. and it should belong to jest core platform

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