question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:34
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
UziTechcommented, Apr 21, 2020

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:

Cannot find module 'prettier' from 'setup_jest_globals.js'
9reactions
SimenBcommented, May 15, 2019

Oh, nice!

A descriptive error message saying “you need to install prettier” might be good enough, too

yeah, we should definitely to that as a first step regardless. #7744

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found