Skip to content

prettier called by toMatchInlineSnapshot throws in typescript test containing any comments #10208

@G-Rath

Description

@G-Rath

🐛 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 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions