-
-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sass support in jest test files appear to be broken #4345
Comments
This is because we don't have scss preprocessor configured for jest. And I am guessing the same problem will be there when we use Can I work on this? |
I'm going to attempt a PR too :) |
Would it be a good idea to follow the 'mocking css modules' section of the jest-webpack documentation found here? https://facebook.github.io/jest/docs/en/webpack.html#mocking-css-modules This would allow tests to check that correct classNames were being applied without having to set up preprocessor transforms. |
This is odd, because we already configured that for CSS Modules (and I believe we even have tests); I wonder why Sass isn't working (or is just not what's expected)? |
Ah, it appears we need to add
|
I'd be happy to make a PR on this, one question however (I cannot seem to find an answer in the documentation I have searched), How am I supposed to test my change with the cloned repo? I cannot see any way to test the changes with a generated create-react-app. Also if I were able to generate an app using the changes, shall I just have the extra generated files not committed then make a PR? Sorry in advance if these are dumb questions. Fairly new to the contributing thing. |
You can test your changes by running You should not commit |
It appears that after modifying So it appears to be importing the sass module as a string of the file name. I'm going to continue looking into this, if this pops out to you as something obvious then feel free to let me know. :) |
I think I have an idea, going to test it tomorrow as generating the node_modules folder every time for CRA is murdering my mobile internet. |
it also appears that importing css modules is not working as expected either.
Using this configuration:
|
Accidental close and comment* |
I'm unsure how to continue this unfortunately, if anyone has some ideas as to the strange behaviour above, otherwise i'll keep this here to see if anyone else wants to pick this up. :) |
Hello, this is still an issue which basically prevents me from testing conditional class assginment as in: const Tile = ({ tilePlacement }) => (
<div className={styles[`tile_${tilePlacement}`] || styles.default} />
) will, in Jest, never return |
Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes
(Write your answer here.)
Which terms did you search for in User Guide?
Sass support
(Write your answer here if relevant.)
Environment
node -v
:npm -v
:yarn --version
(if you use Yarn):npm ls react-scripts
(if you haven’t ejected):Then, specify:
Steps to Reproduce
(Write your steps here:)
1: Update react-scripts to latest release
2: Import styles from 'component.module.scss' in component file
3: Import styles from 'component.module.scss' in component.test.js
Expected Behavior
(Write what you thought would happen.)
Classnames are imported for component file and test file correctly for comparison
see #3815
Actual Behavior
(Write what happened. Please add screenshots!)
Component imports classNames correctly, test file classnames are undefined
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
The text was updated successfully, but these errors were encountered: