styled-components / babel-plugin-styled-components

Improve the debugging experience and add server-side rendering support to styled-components
MIT License
1.07k stars 141 forks source link

[Bug]: babel-plugin-styled-components is ignored/not working starting Jest 27 #406

Open kolesker opened 11 months ago

kolesker commented 11 months ago

Version

2.1.4

Steps to reproduce

  1. Clone my repo https://github.com/kolesker/ts-jest-styled-display-name-bug
  2. Choose jest-26 or jest-29 paths to test
  3. npm install
  4. npm run test

Expected behavior

In jest 26 you get as snapshot:

"<Component>
  <StyledExample>
    <div className=\\"test-issue__StyledExample-sc-yycgxi-0 cxgDRm\\" />
  </StyledExample>
</Component>"
`;

Actual behavior

In jest 29 you get as snapshot:

"<Component>
  <StyledExample>
    <div className=\\"sc-beySbM AIKwo\\" />
  </StyledExample>
</Component>"
`;

Additional context

In the migration from Jest and ts-jest 26 to 29, all of our snapshots are breaking since displayName attribute of babel-styled-components plugin is being ignored. Actually, the issue was introduced when migrating from 26 to 27, but it wasn't solved in the latest 29 version.

The problem is display names in the classes are being completely ignored, while in runtime (non-test environment) it is working OK. Also the issue is only happening after moving out from v26.

Environment

System:
    OS: macOS 13.6.2
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v9.8.1/bin/npm