jhm*_*jhm 7 typescript jestjs react-native expo
我从Jest那里得到了每个手动模拟器的警告,因为它找到了它的.ts和.js版本,并要求我删除一个,即:
jest-haste-map: duplicate manual mock found:
Module name: feedTestData
Duplicate Mock path: /Users/[username]/Documents/git/[projectname]/src/state/ducks/feed/__mocks__/feedTestData.ts
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/Users/[username]/Documents/git/[projectname]/src/state/ducks/feed/__mocks__/feedTestData.ts
Please delete one of the following two files:
/Users/[username]/Documents/git/[projectname]/dist/state/ducks/feed/__mocks__/feedTestData.js
/Users/[username]/Documents/git/[projectname]/src/state/ducks/feed/__mocks__/feedTestData.ts
Run Code Online (Sandbox Code Playgroud)
我已经尝试用exclude我的密钥抄袭tsconfig.json,但我找不到匹配所有__mocks__文件夹的glob模式.
即从我的文件夹中"exclude":["**/__mocks__/*"]删除根__mocks__文件dist夹,但不删除任何子文件夹.
为了它的价值,我正在使用Expo + React Native.我的Jest设置package.json如下所示:
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/",
"<rootDir>/dist/"
],
"cacheDirectory": ".jest/cache",
"collectCoverageFrom": [
"src/**/*.{ts,tsx}",
"!**/node_modules/**",
],
"setupFiles": [
"./src/global-mock-fetch.ts",
"./__mocks__/redux-mock-store.ts"
],
"automock": false
}
Run Code Online (Sandbox Code Playgroud)
Dau*_*eDK 11
是否可以通过指示打字稿不要转换模拟目录中的文件来解决问题?
我在 Angular + jest 设置中取得了成功,在我的 tsconfig 中有以下内容:
"exclude": [
"**/__mocks__/*"
]
Run Code Online (Sandbox Code Playgroud)
我希望它能帮助你。
| 归档时间: |
|
| 查看次数: |
729 次 |
| 最近记录: |