-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inline snapshots for mocked functions #5929
Comments
Mock history is available in const f = vi.fn();
// ... do something with f ...
// ... then dump all calls
expect(f.mock.calls).toMatchInlineSnapshot(`
[
[
1,
],
[
2,
],
]
`); Would it be different from what you suggest? |
Oh this is great! I totally missed this part of the docs for mocked functions 😂. I would argue that it's less intuitive than the syntax I'm proposing here but I think it's a great alternative. With that said, would it be possible for the user/plugin to be able to inject functionality to the inline snapshot updates? |
Can you elaborate what you mean? Are you asking whether it's possible to implement your asymmetric matcher |
Yeah basically. But on second thought the solution you provided is sufficient for any use case really. The asymmetric matcher I'm proposing here is nice to have but I don't feel like it's that important to be implemented inside the framework. I think we can close this issue on this note if you don't have any other take on this. Thanks for letting me know the solution 😄! |
Clear and concise description of the problem
I'm a huge fan of Vitest and I love using the
toMatchInlineSnapshot
when writing test cases and receiving instant feedback. But I think it would be great to have this feature for testing mock function calls intoHave(Nth)BeenCalledWith
,toHave(Nth)ReturnedWith
as an asymmetric matcher.Suggested solution
Alternative
#5929 (comment)
This behavior can be achieved withexpect.extend
and parsing/serializing the snapshots, but I don't think there is a way (or is there a way? please let me know!) to inject snapshot updates on the user end.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: