vitest-dev / vitest-dev/vitest
Components styled with emotion do not get theme from material theme provider
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
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
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.18.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitejs/plugin-react: ^4.2.1 => 4.2.1
@vitest/ui: 1.5.3 => 1.5.3
vite: 5.2.10 => 5.2.10
vitest: 1.5.3 => 1.5.3
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction in test/StyledComponent.test.tsx and run it with the reported Vitest, Vite, and React setup. Compare how the Material UI ThemeProvider behaves in production and tests; done means emotion/styled components receive the Material UI theme during tests without an additional emotion provider.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript, vite
- Domain
- frontend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100