Testing with Vitest
See original GitHub issueHello, any help how test vanilla-extract with Vitest?
Demo: Stackblitz
i have an error with npm run test
FAIL src/components/button/button.test.tsx [ src/components/button/button.test.tsx ]
Error: Styles were unable to be assigned to a file. This is generally caused by one of the following:
- You may have created styles outside of a '.css.ts' context
- You may have incorrect configuration. See https://vanilla-extract.style/documentation/setup
Issue Analytics
- State:
- Created a year ago
- Reactions:15
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Vitest | A blazing fast unit test framework powered by Vite
A blazing fast unit test framework powered by Vite. ... Reuse Vite's config, transformers, resolvers, and plugins - consistent across your app and...
Read more >A guide to Vitest automated testing with Vue components
With Vue component testing, we can test our individual components to verify that they work correctly and that asynchronous operations are ...
Read more >Vitest with React Testing Library - Robin Wieruch
Learn how to use React Testing Library with Vitest in Vite. React Testing Library is a popular testing library for writing tests in...
Read more >Testing with Vitest - This Dot Labs
Vitest is a new testing framework powered by Vite. It's still in development, and some features may not be ready yet, but it's...
Read more >Testing a React application with Vitest - Eternal Dev
Learn about testing React applications with Vitest. We will cover setting up react with vitest and show how to add unit tests and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey All. I ran into this a few weeks ago, it was a pain to debug. The issue is with some code being run in ESM and some in CJS so the file scopes stuff is split across 2 separate modules and therefore cannot see each-others local variables. Long story short you need to include the following in your Vite config:
https://vitest.dev/config/#deps
See fixed fork here: https://stackblitz.com/edit/vitejs-vite-1fmagr?file=vite.config.ts
It looks to be related to this issue: https://github.com/vitest-dev/vitest/issues/747
Similar to the comment in that thread one solution is to delete
node_modules/@vanilla-extract/css/fileScope/package.json
which interferes with the module resolution defined at the top-level (
fallbackCJS: true
did not work for me)