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
{{ message }}
Repository navigation
Sass support in jest test files appear to be broken #4345
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
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)?
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 yarn create-react-app my-app from the base of your cloned repo. That will create a new app called my-app using your local changes.
You should not commit my-app when submitting a PR. You can create my-app outside of your cloned repo by doing something like this instead: yarn create-react-app ../my-app.
It appears that after modifying createJestConfig.js and generating an app, doing the following: import styles from test.module.scss
results in: console.log(styles) // => 'test.module.scss'
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'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. :)
Activity
Aftabnack commentedon Apr 23, 2018
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
.module.cssfiles.Can I work on this?
Tasemu commentedon Apr 23, 2018
I'm going to attempt a PR too :)
Tasemu commentedon Apr 24, 2018
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.
Timer commentedon Apr 24, 2018
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)?
Timer commentedon Apr 24, 2018
Ah, it appears we need to add
{sass,scss}to these locations:https://github.com/facebook/create-react-app/blob/789b856b13693f14d89cb9c4622ae7c8f08a6069/packages/react-scripts/scripts/utils/createJestConfig.js#L46-L49
https://github.com/facebook/create-react-app/blob/789b856b13693f14d89cb9c4622ae7c8f08a6069/packages/react-scripts/scripts/utils/createJestConfig.js#L52
Tasemu commentedon Apr 24, 2018
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.
iansu commentedon Apr 24, 2018
You can test your changes by running
yarn create-react-app my-appfrom the base of your cloned repo. That will create a new app calledmy-appusing your local changes.You should not commit
my-appwhen submitting a PR. You can createmy-appoutside of your cloned repo by doing something like this instead:yarn create-react-app ../my-app.Tasemu commentedon Apr 24, 2018
It appears that after modifying
createJestConfig.jsand generating an app, doing the following:import styles from test.module.scssresults in:
console.log(styles) // => 'test.module.scss'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. :)
Tasemu commentedon Apr 24, 2018
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.
Tasemu commentedon Apr 25, 2018
it also appears that importing css modules is not working as expected either.
Using this configuration:
Tasemu commentedon Apr 25, 2018
Accidental close and comment*
Tasemu commentedon Apr 27, 2018
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. :)
dawidsok commentedon Oct 23, 2018
Hello, this is still an issue which basically prevents me from testing conditional class assginment as in:
will, in Jest, never return
defaultbuttile_[tilePlacementValue]