jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.28k stars 6.47k forks source link

[Feature]: [pretty-format] make it easier to copy-paste the output of an assertion failure to JS again #15347

Open eliasm307 opened 1 month ago

eliasm307 commented 1 month ago

🚀 Feature Proposal

Similar to https://github.com/jestjs/jest/issues/10730 this is a request for assertion output to not include the "Array" and "Object" names from assertion output diff

Motivation

Instead of using toMatchInlineSnapshot I use the regular value assertions e.g. toEqual and in some cases where I know some current behaviour is correct, I run the test with an empty value e.g. an empty object or something, then copy the assertion failure diff as the new expectation.

The issue is that the assertion failure diff requires formatting, e.g. removing the "+" characters, which is acceptable, but in some cases I also need to remove the inline prototype names that are added.

It would be good if there was an option like exists for snapshots to turn this off for some values in the same way as done in https://github.com/jestjs/jest/issues/10730

Example

From this assertion

    expect({
      obj: { foo: 'bar' },
      array: [1, 2, 3],
      set: new Set([1, 2, 3]),
    }).toEqual({});

the output is:

image

the "Set" is acceptable, but ideally an option for "Object" and "Array" to not be shown would be good

Pitch

For similar reasons https://github.com/jestjs/jest/issues/10730 was added

github-actions[bot] commented 20 hours ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

eliasm307 commented 16 hours ago

Commenting to keep active, pending feedback