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
if you prefer cssTransform.cjs, you can use this instead, it will work.
but only cjs works in my case, ts, js, mjs doesnt.
the order of ts-jest vs jest-preview/transforms/css seems doesnt matter
jest config setupFilessetupFilesAfterEnv were not used (they are there, but they are just empty)
import styles from .module.css in your test file & add some npm package
the problem I had was:
even after I setup the css transform in jest config file,
no css module was imported,
-- the style.css_WhateverName is always undefined.
event though the jest-preview command works
& the jest test does run normally.
(other github issue & online posts didnt help
tried so many ways to change & test & guess the transform, not working. )
one thing did help when I run the jest test is:
the error log told me to install postcss
& told me to install other postcss package
at some point, no more error logs
however, occasionally some error log is printed,, when I run jest test,, after the transform config is changed.
& it talks about other more postcss package & string-hash to install.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
environment
Im using
React, Vite, Typescript, Jest, React testing library, Jest with esm (node --experimental-vm-modules), jest-preview, css module
install more
postcss
package is the key for my fixfollowing worked in my case, but still it can very dep on your environment
hopefully I didnt miss something
procedure to use css module in jest_preview
set up css transform
see https://www.jest-preview.com/docs/getting-started/installation
add:
remove:
my jest config file
H:\Using\TLightChat\tlightchat-main\jest.config.js
(ignore the comments)
import styles from .module.css in your test file
my test file
H:\Using\TLightChat\tlightchat-main\test\_introTryTest\JestPreview_introTryTest.test.tsx
add some npm package
some comments
set up css transform
following is not needed in my case:
following is not needed in my case:
see https://www.jest-preview.com/docs/advanced-guides/code-transform
if you prefer
cssTransform.cjs
, you can use this instead, it will work.but only cjs works in my case, ts, js, mjs doesnt.
the order of
ts-jest
vsjest-preview/transforms/css
seems doesnt matterjest config
setupFiles
setupFilesAfterEnv
were not used (they are there, but they are just empty)import styles from .module.css in your test file & add some npm package
the problem I had was:
even after I setup the css transform in jest config file,
no css module was imported,
-- the
style.css_WhateverName
is alwaysundefined
.event though the
jest-preview
command works& the jest test does run normally.
(other github issue & online posts didnt help
tried so many ways to change & test & guess the
transform
, not working. )one thing did help when I run the jest test is:
the error log told me to install
postcss
& told me to install other postcss package
at some point, no more error logs
however, occasionally some error log is printed,, when I run jest test,, after the
transform
config is changed.& it talks about other more
postcss
package &string-hash
to install.can be related to Cannot process CSS modules in CRA #254
Beta Was this translation helpful? Give feedback.
All reactions