Skip to content

Do not highlight passing asymmetric matchers in diffs #6184

Closed
@MarkyMarkMcDonald

Description

@MarkyMarkMcDonald

🚀 Feature Proposal

This is another idea related to more helpful failure diffs in the same vein as #6170.
The diff of a failing expectation currently highlights nested usages of expect.objectContaining and expect.anything because they are not "equal" to whatever was received. I propose only printing out a diff if the matcher fails.

Motivation

Both this issue and #6170 are the product of a pairing session where we had a hard time tracking down what the actual error was when an existing test started failing. I think that test could have been broken up into several more specific tests or used chained expectations, but it would have been nice to pinpoint the failing property right away.

Example

Here's an example of a failing test that uses a combination of matchers:

https://repl.it/repls/DifficultSvelteMonitors
image

The only property that doesn't match is "rank" due to a type mismatch, but it's hard to see that when scanning the failure diff because the nested matchers are displaying.

The desired approach would look like this:
image

Pitch

Why does this feature belong in the Jest core platform?

This is a change to the default reporter that will help identify the cause of failures faster.

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