Closed shahzainb closed 6 years ago
👍 I was about to create an issue on the same topic!
There must have been an update to Jest or something as it was previously working (and has/had working test in CRA).
Happy for you to do a PR here, and even better a PR to CRA as well :)
you right, it looks like the CRA repo actually has it.
a rebase on the latest tag should do the magic.
the change is on the CRA master branch, but it has not been released under any tag so far. :(
Any idea how we could approach it?
This should be the same as CRA, as this was made to house cssmodules until they were merged.
If something isn't working in this repo. Feel free to do the PR here. And then I can advise how to address it in CRA (if it needs to be).
On 7/03/2018 5:10 PM, "Anderson Saunders" notifications@github.com wrote:
the change is on the CRA master branch, but it has not been released under any tag so far. :(
Any idea how we could approach it?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ro-savage/react-scripts-cssmodules/issues/5#issuecomment-371034184, or mute the thread https://github.com/notifications/unsubscribe-auth/AI0PWxnuo0yiHq_HV0faYBDH43Oormlbks5tb3nugaJpZM4Scpzd .
Hi @ro-savage,
At the moment, Jest isn't able to mock the styles object that would be imported from a CSS module. This issue occurs if you're trying to test the availability of a className within a spec.
For example, below I've put some sample code for a button:
PrimaryButton.spec.js:
PrimaryButton.js:
PrimaryButton.module.css
Building this through react-scripts-cssmodules works perfectly fine, and the classnames are outputted with the expected identName as per the config (
[path]__[name]__[local]
). However, while testing, the class attribute ends up being empty.The solution I found for this, was to add a config within Jest moduleNameMapper to include
identity-obj-proxy
. I've forked the project and committed it here: https://github.com/shahzainb/react-scripts-cssmodules/commit/ca286090fc3693a474e2d47606497a6d86801a76I found the solution on the Jest documenation: https://facebook.github.io/jest/docs/en/webpack.html#mocking-css-modules
Please let me know if this is a valid issue, and if you're ok with me creating a PR for this.
Thanks.