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 called by `toMatchInlineSnapshot` throws in typescript test containing any comments

See original GitHub issue

🐛 Bug Report

When using toMatchInlineSnapshot in a typescript test with a comment, an error is thrown:

TypeError: Property comments[0] of File expected node to be of a type ["Comment"] but instead got "Line"

      at validate (node_modules/@babel/types/lib/definitions/utils.js:132:11)
      at Object.validator [as validate] (node_modules/@babel/types/lib/definitions/utils.js:103:7)
      at validateField (node_modules/@babel/types/lib/validators/validate.js:24:9)
      at validate (node_modules/@babel/types/lib/validators/validate.js:17:3)
      at builder (node_modules/@babel/types/lib/builders/builder.js:38:27)
      at File (node_modules/@babel/types/lib/builders/generated/index.js:318:31)
      at Object.parse (node_modules/prettier/index.js:9739:19)
      at coreFormat (node_modules/prettier/index.js:13252:23)
      at format (node_modules/prettier/index.js:13510:73)
      at formatWithCursor (node_modules/prettier/index.js:13526:12)
      at node_modules/prettier/index.js:44207:15
      at Object.format (node_modules/prettier/index.js:44226:12)

This seems to be because of a change in a dependency, as it doesn’t happen with eslint-plugin-eslint-config which I was working on last week.

To Reproduce

// file.test.ts
it('is true', () => {
  // this will not end well...

  expect(true).toMatchInlineSnapshot();
});

Expected behavior

The test to pass, and the snapshot to be written.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: Linux 4.4 Ubuntu 18.04.4 LTS (Bionic Beaver)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 14.4.0 - ~/.nodenv/versions/14.4.0/bin/node
    Yarn: 1.22.4 - ~/.nodenv/versions/14.4.0/bin/yarn
    npm: 6.14.5 - ~/.nodenv/versions/14.4.0/bin/npm
  npmPackages:
    jest: ^26.0.0 => 26.1.0 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
JLHwungcommented, Jun 30, 2020

It is fixed in @babel/types 7.10.4

1reaction
G-Rathcommented, Jun 30, 2020

@JLHwung awesome, cheers for such a fast turnaround!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expect - Jest
The expect function is used every time you want to test a value. You will rarely call expect by itself. Instead, you will...
Read more >
Prettier 2.5: TypeScript 4.5 and MDX v2 comment syntax!
Starting with Prettier 2.3.0, type declarations in arrow functions could affect function body indentation. Changing the length of the type ...
Read more >
Jest testing: Top features and how to use them - LogRocket Blog
What is Jest? Top features of Jest. Snapshot testing; Interactive mode; Out-of-the-box ease; Debugging Jest tests with VSCode ...
Read more >
Writing Cleaner Tests with Jest Extensions
Introduction While developing scss-codemods I wrote tests to ensure changes for new featur... Tagged with postcss, javascript, codequality, ...
Read more >
Guide to testing in React - my software development blog
(If you disagree, let me know in the comments). For that reason I'm going to focus on React Testing Library (RTL). And we...
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