-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The moduleNameMapper
configuration only works with regexes that match the whole path. I found this out when working on facebook/create-react-app#584. When using this configuration the modules were stubbed correctly:
moduleNameMapper: {
'^.+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
'^.+\\.css$': resolve('config/jest/CSSStub.js')
},
But changing it to following caused them to not be stubbed:
moduleNameMapper: {
'\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
'\\.css$': resolve('config/jest/CSSStub.js')
},
Upon further investigation, I found out that this line in jest-resolve
uses the same regex to replace the module name with the mapped name, and if the regex doesn't match the whole path, it doesn't get replaced correctly.
What is the expected behavior?
Expected to be able to use regexes like \\.css$
that only match the end of the path.
sheepsteak