Skip to content

Don't highlight passing asymmetric matchers as changes in diffs #7027

Closed
@calebeby

Description

🚀 Feature Proposal

Hi 👋. I think it would be great if Jest would better highlight diffs for objects with asymmetric matchers. Currently, Jest highlights correct/passing asymmetric matchers as changes, which is confusing to the user. I propose that Jest only highlights the matchers that do not pass.

For example:

test('asdf', () => {
  expect({ name: 'asdf' }).toStrictEqual({
    name: expect.any(String),
    week: expect.any(Number),
  })
})

screenshot-1537659092

This output is unclear to the user. It shows that the name property is different from the expected value, which makes it less clear that the week property is missing. Objects with more properties make it harder and harder to tell the actual changes.

I propose that Jest highlights the above example like:

- Expected
+ Received

  Object {
    "name": "asdf",
-   "week": Any<Number>,
  }

This would make it much more clear to the user which property is missing.

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