Prettier is used by `toMatchInlineSnapshot`, but it is not a dependency of `jest`
See original GitHub issue🐛 Bug Report
Prettier is used by jest for toMatchInlineSnapshot
, but since it’s not a dependency of jest
, toMatchInlineSnapshot
only works if some other package depends on prettier (or it’s in the user’s package.json
).
To Reproduce
Steps to reproduce the behavior:
- Make a new directory and run
yarn init --yes
inside it - Run
yarn add jest
- Create a test using the
toMatchInlineSnapshot
matcher, eg:expect(2 + 2).toMatchInlineSnapshot()
- Notice that the test fails with an error indicating that prettier cannot be found.
Expected behavior
Test passes with no issues
npx envinfo --preset jest
System:
OS: macOS 10.14.4
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 12.1.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
npmPackages:
jest: 24.8.0 => 24.8.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:34
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Prettier is used by `toMatchInlineSnapshot`, but it is not a ...
Prettier is used by `toMatchInlineSnapshot `, but it is not a dependency of `jest`
Read more >reactjs - Error running a Jest snapshot test using a custom ...
Removing the snapshotSerializers entry from jest config and adding the jest-styled-components import into the test file resolved this issue.
Read more >Configuring Jest
Jest attempts to scan your dependency tree once (up-front) and cache it in order to ease some of the filesystem churn that needs...
Read more >CLI - Prettier
Use the prettier command to run Prettier from the command line. ... To run your locally installed version of Prettier, prefix the command...
Read more >jest-resolve-dependencies | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
looks like it is supposed to throw a descriptive error message:
https://github.com/facebook/jest/blob/fa4cbbf87cb3c97fe44f1fee30663715a9dbba71/packages/jest-snapshot/src/inline_snapshots.ts#L33-L35
The error message that I get with
jest-cli@25.4.0
is:Oh, nice!
yeah, we should definitely to that as a first step regardless. #7744