Reputation: 165
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?
Upvotes: 12
Views: 4192
Reputation: 10936
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"
Upvotes: 8