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

Confusing error on missing toMatchSnapshot() argument #6581

Closed
gaearon opened this issue Jun 30, 2018 · 4 comments · Fixed by #6528
Closed

Confusing error on missing toMatchSnapshot() argument #6581

gaearon opened this issue Jun 30, 2018 · 4 comments · Fixed by #6528
Assignees

Comments

@gaearon
Copy link
Contributor

gaearon commented Jun 30, 2018

🐛 Bug Report

When toMatchSnapshot(propertyMatchers, snapshotName) has null as the first argument, Jest prints a confusing error:

  Received value does not match snapshot properties for "foo: hello 1".

    Expected snapshot to match properties:
      null
    Received:
      "foo"

To Reproduce

Steps to reproduce the behavior:

it('foo', () =>
  expect('foo').toMatchSnapshot(null, 'hello')
);

with Jest 23

Expected behavior

I only wanted to specify snapshotName. The docs say it's the second argument: http://jestjs.io/docs/en/expect.html#tomatchsnapshotpropertymatchers-snapshotname

I have no idea what "property matchers" are and am not currently interested in them. (The docs fail to mention their format.) I passed null because I don't know what their default value is (the docs fail to mention that too).

I couldn't figure out for quite some time why my tests were failing. I expected null to be treated as a "missing" value for propertyMatchers instead of trying to treat it as some kind of a shape.

Link to repl or repo (highly encouraged)

Repl seems to be on an older Jest version without this problem.

But the above repro works for a clear Jest 23 install.

@gaearon
Copy link
Contributor Author

gaearon commented Jun 30, 2018

The most confusing part of this experience was Jest telling me to re-run my snapshots with -u to record changes, but -u not doing anything. I wasted some time digging why -u wasn't being passed to CLI (which it actually was).

@SimenB
Copy link
Member

SimenB commented Jun 30, 2018

You can do expect('foo').toMatchSnapshot('hello'). That should definitely be in the docs. Wanna send a PR for it?

@rickhanlonii we should improve the error message here

@rickhanlonii
Copy link
Member

fwiw the docs say that the property matchers are optional

I added a better error message here: #6528

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants