You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having a react app using material ui and emotion/styled, components styled with emotion/styled do not receive the theme from the material ui ThemeProvider in tests.
This is working for production code.
As a workaround one could wrap the tested component into an additional theme provider from emotions. See also this stack overflow discussion.
stderr | node_modules/@ emotion/react/dist/emotion-react.esm.js:472:15
You are loading @emotion/react when it is already loaded. Running multiple instances may cause problems. This can happen if multiple versions are used, or if multiple builds of the same version are used.
this is a dual package issue of @emotion/react. The one imported through @mui/material (via NodeJS) and the other from your source code (via Vite/Vitest) are seeing different context singleton.
Looking at https://publint.dev/@emotion/react@11.11.4, the package exports is quite complicated, but seems legitimate, so it might be possible that Vite / Vitest's default resolution is doing something wrong.
Well as workaround this works but I think it is not good that vite and vitest behave in a different way.
Isn't there a way to force the loading of the correct module on vitest side?
Describe the bug
Having a react app using material ui and emotion/styled, components styled with emotion/styled do not receive the theme from the material ui ThemeProvider in tests.
This is working for production code.
As a workaround one could wrap the tested component into an additional theme provider from emotions. See also this stack overflow discussion.
Reproduction
A minimal example can be found in this StackBlitz sandbox
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: