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

How might we utilize snapshots for arguments matching? #17

Whoaa512 opened this Issue Apr 5, 2019 · 1 comment


None yet
2 participants
Copy link

Whoaa512 commented Apr 5, 2019

I have a use case where I'm generating a relatively large payload and I'd like when to make a snapshot for one of the arguments.

Example code

import { when } from 'jest-when'

const fn = jest.fn()

test('match snap', () => {


    expect(fn({ bar: { a: 12 } })).toEqual('hi')

Basically I want to jest-when to look at the arg and if I pass the asymmetric snapshot matcher to use expect(arg).toMatchSnapshot() instead of the normal .toEqual

What do you think?

For context, expect.toMatchSnapshot() is only available in jest 23+, and even then expect.toMatchSnapshot() doesn't actually work like you'd expect.


This comment has been minimized.

Copy link

timkindberg commented Apr 5, 2019

I don't think you can use toMatchSnapshot in that fashion... it has to be used as an assertion only. I think you'd have to import the payload then assert it equals the snapshot then pass it to expectCalledWith.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.