Skip to content

[Feature]: Support array inputs to toMatchSnapshot() matcher #13352

@bjoluc

Description

@bjoluc

🚀 Feature Proposal

Currently,

expect([{}]).toMatchSnapshot([expect.anything()]);

fails with

expect(received).toMatchSnapshot(properties)

Matcher error: Expected properties must be an object

Expected properties has type:  array
Expected properties has value: [Anything]

(#13134, example repo here).

Motivation

This used to work in Jest v27 and would allow test cases like this again. It would help to avoid wrapping arrays in objects solely for the sake of snapshot testing.

Example

Something like

expect([{}, "foo"]).toMatchSnapshot([expect.anything(), "foo"]);

Pitch

This was supported in Jest v27 and the wording toMatchSnapshot feels very intuitive as opposed to some custom toMatchArraySnapshot (or the like) matcher. As a neat side effect, this would also allow to snapshot-test function parameter arrays.

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