Skip to content

"TypeError: Cannot set property 'originalText' of undefined" from TypeScript Jest inline snapshot #11888

@joshkel

Description

@joshkel

After upgrading from Prettier 2.4.x to 2.5.0, a Jest inline snapshot test in a TypeScript file throws the following error when Jest tries to update the snapshot:

    TypeError: Cannot set property 'originalText' of undefined

      at Object.<anonymous> (node_modules/prettier/parser-typescript.js:13:3304772)
      at Object.parse$d [as parse] (node_modules/prettier/index.js:12975:19)
      at coreFormat (node_modules/prettier/index.js:14525:16)
      at formatWithCursor$1 (node_modules/prettier/index.js:14765:14)
      at node_modules/prettier/index.js:60955:12
      at Object.format (node_modules/prettier/index.js:60975:12)

I'm not sure if this is a bug within Prettier or within how Jest is using Prettier; if I should file this with the Jest project, please let me know.

Environments:

  • Prettier Version: 2.5.0
  • Running Prettier via: CLI (via Jest)
  • Runtime: Node.js 14.17.1
  • Operating System: Windows and Linux
  • Prettier plugins (if any): None

Steps to reproduce:

Clone https://github.com/joshkel/prettier-test-case and run npm i; npm test

Expected behavior:

The snapshot is correctly written and Prettier formats the file.

Actual behavior:

Abort with a stack trace.

Metadata

Metadata

Assignees

Labels

area:apiIssues with Prettier's Application Programming Interface

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions