Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest inline snapshot testing fails when prettier-plugin-tailwind is installed #25

Open
TimonVS opened this issue Mar 3, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@TimonVS
Copy link

TimonVS commented Mar 3, 2021

Describe the bug

First of all, thanks for this wonderful plugin!

I'm running into some problems when using this plugin with Jest. Inline snapshot testing (toMatchInlineSnapshot) in Jest uses Prettier (https://jestjs.io/docs/en/snapshot-testing#inline-snapshots), tests using inline snapshot testing start to fail as soon as you install prettier-plugin-tailwind, tests that use non-inline snapshot testing or no snapshot testing at all work just fine.

 FAIL  src/landing-page/landing-page-paths.test.ts
  ● Test suite failed to run

    TypeError: Cannot read property 'twJsxClassAttributes' of undefined

      at Object.parse (node_modules/prettier-plugin-tailwind/lib/parsers/typescript.js:19:40)
      at Object.parse (node_modules/prettier/index.js:13625:19)
      at coreFormat (node_modules/prettier/index.js:14899:14)
      at format (node_modules/prettier/index.js:15131:14)
      at node_modules/prettier/index.js:57542:12
      at Object.format (node_modules/prettier/index.js:57562:12)

I did a bit of debugging and it boils down to the options argument in the parse function being undefined when ran by Prettier in Jest: https://github.com/Acidic9/prettier-plugin-tailwind/blob/master/src/parsers/typescript.ts#L12.

I'm not yet sure if this is a bug with plugin-prettier-tailwind, Jest or Prettier. I'm hoping someone with more knowledge about the internal workings of these tools might shed some light on that :)

To Reproduce

https://codesandbox.io/s/nameless-river-f9fuy?file=/index.test.js

Expected behavior

Inline snapshots should be formatted with plugin-prettier-tailwind.

Versions:

  • prettier-plugin-tailwind version: 2.2.9
  • Operating system: macOS
  • NPM/Yarn version: 6.14.5
@TimonVS TimonVS added the bug Something isn't working label Mar 3, 2021
@peterp
Copy link

peterp commented Mar 16, 2021

I'm having the same issue.

@thebuilder
Copy link
Contributor

Thinking it would make sense to simply have it skip running the prettier task if the options are undefined. It's just used to by Jest to ensure consistent formatting of the snapshot code, so it doesn't make sense to format the tailwind code anyway.

@kik4
Copy link
Contributor

kik4 commented Oct 25, 2021

I'm having the same problem.

@cassus
Copy link

cassus commented May 21, 2022

#41 and upgrading to the latest version fixed it for me. Thanks @kik4 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants