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

Cannot generate Jest image snapshot - getting error "TypeError: matcher.apply is not a function" #5086

Closed
basher opened this issue Sep 25, 2018 · 4 comments

Comments

@basher
Copy link

basher commented Sep 25, 2018

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Yes.

But I've started again with a fresh instance of Create React App (Git repo link further down...).

Which terms did you search for in User Guide?

"jest", "snapshot"

Environment

Environment:
OS: Windows 10
Node: 8.11.1
Yarn: 1.7.0
npm: 5.6.0
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.1.0.0 AI-173.4819257

Packages: (wanted => installed)
react: ^16.5.2 => 16.5.2
react-dom: ^16.5.2 => 16.5.2
react-scripts: ^1.1.4 => 1.1.4

Steps to Reproduce

Git repo (link below...) has README which explains issue.

Basically...

  1. yarn test and yarn coverage both function correctly on "./src/App.test.js".
  2. Adding an additional "jest-image-snapshot" test (with appropriate dependencies - e.g. Puppeteer) breaks the test, with a Node error as specified in title of this bug.
  3. Moving the image snapshot test to a folder OUTSIDE "./src" and running it independently via a Node script from "package.json", I get the same Node error.

Expected Behavior

I expected a PNG snapshot image to have been created from the rendered browser output. No image is generated.

Actual Behavior

Test fails to complete, with a Node error, as per title of this bug.

Reproducible Demo

See bug-jest-image-snaphot

@basher basher changed the title Cannot generate image snapshot - getting error "TypeError: matcher.apply is not a function" Cannot generate Jest image snapshot - getting error "TypeError: matcher.apply is not a function" Sep 25, 2018
@basher
Copy link
Author

basher commented Sep 26, 2018

Wondering whether an update to Jest 23 as part of React Scripts update to V2 will help?

  • Any idea when V2 will be available?
  • And what potential issues there might be compared to V1.1.4?

@basher
Copy link
Author

basher commented Sep 28, 2018

I've bumped react-scripts to V2 (beta).

Still get same error - TypeError: matcher.apply is not a function

@bugzpodder
Copy link

Change your code to import { toMatchImageSnapshot } from 'jest-image-snapshot'; and it should work. (notice the curly braces)

@basher
Copy link
Author

basher commented Oct 1, 2018

Change your code to import { toMatchImageSnapshot } from 'jest-image-snapshot'; and it should work. (notice the curly braces)

@bugzpodder Thanks Jack. Why didn't I spot that?!

@lock lock bot locked and limited conversation to collaborators Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants