Closed supminn closed 4 months ago
@supminn Can you please share your jest configuration file / or a project link where this is reproducible?
Hi @khusharth Thanks for reaching out. Here's my package https://github.com/supminn/monorepo-lerna-demo/tree/master/packages/app-atoms (app-atoms).
I have created a react app using Vite. I tried to create unit tests using vitest. Since I have used styled-components, I was trying to test the styles using jest-styled-components.
Do let me know how I can fix this issue. Thanks.
That's because Vitest by default does not expose test
, expect
, beforeEach
etc. as globals, like jest does. You can make it easily work by changing that with a configuration: https://vitest.dev/config/#globals
However I'd love to see jest-styled-components
enable an option to set up the before hooks without needing to expose globals, because not having globals is preferable in general.
These expect calls would also hit issues without globals, https://github.com/styled-components/jest-styled-components/blob/main/src/utils.js#L72-L74
So it's more than just the hooks sadly
I found the solution in @ggdaltoso's
{
"test": {
"globals": true,
"setupFiles": ["jest-styled-components"]
}
}
I found the solution in @ggdaltoso's
{ "test": { "globals": true, "setupFiles": ["jest-styled-components"] } }
This worked! Thank you soo much. Closing this issue.
I am new to
jest-styled-components
. I have created a react component and added styles usingstyled-components
However, while adding the following test, I am getting these errors:Component
Test file
Package version
Error Message screenshot
Note: I tried to downgrade a few versions of
jest-styled-components
andstyled-components
but could not surpass this issue. Could you please share the possible fixes.