The tutorial for using jest with webpack mentions this syntax: $1, and I haven't been able to figure out what it does. I'm working on two projects with the same aliases, but one works with jest config:
"moduleNameMapper": {
"^myModule(.*)$": "<rootDir>/src/components/react",
}
while one works with
"moduleNameMapper": {
"^myModule(.*)$": "<rootDir>/src/components/react$1",
}
What does the $1 syntax do?
Jest will take the key of the object, and wrap it with a RegExp
object. so basically you are writing a regular expression string as the key. The $1..$9 in regular expressions are the capture groups captured for the match . A capture group is created by wrapping parenthesis around the pattern you want to "save".
"^myModule(.*)$": "<rootDir>/src/components/react$1"
so if you have an import of myModule/SOMETHING
it will be mapped to:
myModule/SOMETHING => <rootDir>/src/components/react/SOMETHING"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With