Skip to content

Commit 2f30280

Browse files
authored
Add CSS mock removal to test setup docs (#724)
1 parent 8467fc2 commit 2f30280

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

site/docs/setup.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,34 @@ $ npm install @vanilla-extract/babel-plugin
287287
}
288288
```
289289
290-
3/ Disable runtime styles (Optional)
290+
3/ Remove any existing `.css` file mocks
291+
292+
It is very common in Jest setups to have a mock file returned for all `.css` files. This clashes with vanilla-extract as Jest can't differentiate between `.css` and `.css.ts` imports.
293+
294+
```json
295+
{
296+
"jest": {
297+
"moduleNameMapper": {
298+
"\\.css$": "<rootDir>/styleMock.js"
299+
}
300+
}
301+
}
302+
```
303+
304+
Ideally, remove this mock from your setup. However, if you need to support both at the same time you'll need a way to target your regular CSS files. Using a folder for all your CSS files, or giving your CSS files a custom extension will work.
305+
306+
```json
307+
{
308+
"jest": {
309+
"moduleNameMapper": {
310+
"my-css-folder/.*\\.css$": "<rootDir>/styleMock.js",
311+
"\\.legacy\\.css$": "<rootDir>/styleMock.js"
312+
}
313+
}
314+
}
315+
```
316+
317+
4/ Disable runtime styles (Optional)
291318
292319
In testing environments (like `jsdom`) vanilla-extract will create and insert styles. While this is often desirable, it can be a major slowdown in your tests. If your tests don’t require styles to be available, the `disableRuntimeStyles` import will disable all style creation.
293320

0 commit comments

Comments
 (0)