styled-components / jest-styled-components

🔧 💅 Jest utilities for Styled Components
MIT License
1.58k stars 144 forks source link

getHTML() is failing, not sure why. #401

Open jisaacks opened 2 years ago

jisaacks commented 2 years ago

I keep getting:

No style rules found on passed Component

I have been able to trace it to this line: https://github.com/styled-components/jest-styled-components/blob/4b07fde2607516db407a6215d17dfb461b90b491/src/utils.js#L25

  const getHTML = () => (isServer() ? new ServerStyleSheet().getStyleTags() : sheet.toString());

My tests are running in node, so isServer is returning true, but new ServerStyleSheet().getStyleTags() is returning an empty string. However if I force it to instead use sheet.toString() everything works as expected and my tests pass/fail as expected.

jisaacks commented 2 years ago

Any help on this?

If I manually edit that line to be:

const getHTML = () => (sheet.toString());

Everything works as expected.

I would hate to have to fork this project just to make that change tho.

Would love some help or pointed in the right direction to determine why isServer() is true but new ServerStyleSheet().getStyleTags() returns an empty string, even tho sheet.toString() works as expected.

Thanks.