Leo*_*Leo 3 javascript testing reactjs webpack jestjs
我遇到了以下问题。仅供参考,我是 Jest 的初学者,所以请让我知道配置 Jest 时出了什么问题。
webpack.config.js
...
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.scss'],
alias: {
'webextension-polyfill-ts': path.resolve(
path.join(__dirname, 'node_modules', 'webextension-polyfill-ts')
),
reducers: path.resolve(__dirname, 'source/redux'),
routers: path.resolve(__dirname, 'source/routers'),
source: path.resolve(__dirname, 'source'),
...
},
},
...
Run Code Online (Sandbox Code Playgroud)
这是 Jest 配置package.json
"jest": {
...
"moduleNameMapper": {
"^reducers": "<rootDir>/source/redux/$1",
"^routers": "<rootDir>/source/routers/$1",
"^source": "<rootDir>/source/$1",
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
但我在运行测试文件时遇到以下错误。
Configuration error:
Could not locate module source-map-support mapped as:
/Volumes/WORK/Development/project/source/$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^source/": "/Volumes/WORK/Development/project/source/$1"
},
"resolver": undefined
}
Run Code Online (Sandbox Code Playgroud)
该问题看起来像是您为 设定了错误的模式moduleNameMapper。正确的应该是:
{
"moduleNameMapper": {
"^reducers/(.*)$": "<rootDir>/source/redux/$1", // You missed the 2nd part `/(.*)`
// ...
...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1829 次 |
| 最近记录: |