You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constconfig={moduleNameMapper: {"^@Foobar(/.*)?$": "<rootDir>/src/components/Foobar$1",// Path to any folder with an index.js}}
Put this in any file tested by jest
importFoobarfrom"@Foobar";
Run a test for that file.
Expected behavior
The test should execute normally.
Actual behavior
The test will fail because jest-resolve didn't find the component
● Test suite failed to run
Configuration error:
Could not locate module @Foobar mapped as:
C:\Users\nikho\jest-test\src\components\Foobar$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^@Foobar(\/.*)?$/": "C:\Users\nikho\jest-test\src\components\Foobar$1"
},
"resolver": undefined
}
This is because when the capture group (/.*)? is not matched it will get the value undefined in the object returned by String.prototype.match, and this is coerced to a string instead of replaced with an empty string, so jest-resolve will try to find the component Foobarundefined instead of Foobar. Simply adding || "" to line 442 should fix the issue.
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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Version
29.6.4
Steps to reproduce
Expected behavior
The test should execute normally.
Actual behavior
The test will fail because jest-resolve didn't find the component
This is because when the capture group
(/.*)?
is not matched it will get the valueundefined
in the object returned by String.prototype.match, and this is coerced to a string instead of replaced with an empty string, so jest-resolve will try to find the component Foobarundefined instead of Foobar. Simply adding|| ""
to line 442 should fix the issue.jest/packages/jest-resolve/src/resolver.ts
Lines 440 to 443 in 3738e3f
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: