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 · 0 comments
Open

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

MillerSvt opened this issue Dec 30, 2024 · 0 comments

Comments

@MillerSvt
Copy link

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

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