Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add asymmetric matcher for comparing with snapshot #15432

Open
MillerSvt opened this issue Dec 30, 2024 · 1 comment
Open

[Feature]: Add asymmetric matcher for comparing with snapshot #15432

MillerSvt opened this issue Dec 30, 2024 · 1 comment

Comments

@MillerSvt
Copy link
Contributor

MillerSvt commented Dec 30, 2024

🚀 Feature Proposal

Sometimes there is a need to check complex objects in checking calls to the function. This is often due to the definition of some large mock object that would satisfy the condition. But this makes the test code less readable.

I suggest adding an asymmetric matcher expect.matchSnapshot(name) to solve this problem.

For a detailed description of the desired API, see the Examples section.

Motivation

This proposal will simplify the code of tests by making checks in snapshots.

Example

expect(func).toHaveBeedCalledWith('foo', 123, expect.matchSnapshot());
// equivalent to
expect(func).toHaveBeedCalledWith('foo', 123, expect.anything());
expect(func.mock.calls[0][2]).toMatchSnapshot();

// ---

expect(func).toHaveBeedCalledWith('foo', 123, expect.matchSnapshot('some name'));
// equivalent to
expect(func).toHaveBeedCalledWith('foo', 123, expect.anything());
expect(func.mock.calls[0][2]).toMatchSnapshot('some name');

Pitch

Copy link

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.

@github-actions github-actions bot added the Stale label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant