-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
/scss/ in preprocessorIgnorePatterns has no effect #870
Comments
Any updates on this? |
This doesn't work because ignoring scss from the preprocessor just means that it will not be run through babel-jest. Jest will then try to require the scss file directly and then fail because it isn't valid JavaScript. There are two solutions: Use the
|
The "moduleNameMapper": {
"^.*\\.scss$": "./src/shared/test/SCSSStub.js"
} Now requiring SCSS in Jest works exactly like requiring CSS. |
that's great! |
preprocessorIgnorePatterns does not need slashes around the entries. It should work with I worked around that by having my preprocessor return an empty string if the filename ends in |
@cpojer I just tried upgrading to v16.0.1 (from v14.1.0) and all our tests now fail because it complains about syntax errors related jest setup:
styleMock.js
|
@iam-peekay I was getting the same error due to sass imports. Following the instructions in the Jest webpack tutorial resolved the issue for me - specifically adding the moduleNameMapper for files and styles, and the mocks they reference. |
Took me a while to get this to work for me because I thought the path was relative to the project. Below works for me:
SassStub.js
|
Hi guys, I'm running into this problem too. What is a SassStub.js file? What goes inside it? Can't find anything about it. |
@leongaban See #870 (comment): SassStub.js
|
Just a note for future readers, the I wanted to stub style imported in modules, something like:
So I created a style stub file:
After messing around with the following
The The solution was to put specific rules first.
|
@emileber it's generally advised to have as |
@thymikee Regexes are a maintenance nightmare, so keeping them as simple as possible is best in my opinion. I feel like it's much more likely that any confusion in this regard comes from the missing documentation rather than under-specific regexes. |
@emileber interested in contributing to docs? 🙂 Patterns are indeed checked one-by-one until they fit and then bailout. |
Struggling to get this to work, I have:
And I'm not exactly sure where to put the emptyTestModule, I've tried both the root and
Edit: I fixed this by using rootDir: |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We're using CSS modules in our React components, which are importing
.scss
files, like this:To ignore them when running jest, I've excluded
/scss/
from the module loader (or so I think):However, when running the tests, the module loader still tries (and fails) to parse the .scss file as javascript and yields this error:
Any variation of the exclude Pattern, such as
\\.scss
,scss
and so forth has no effect.We're using
babel-jest
as thescriptPreprocessor
(so no specific entry for that in package.json)The text was updated successfully, but these errors were encountered: