【发布时间】:2018-08-29 12:31:30
【问题描述】:
对于我拥有的每个手动模拟,我都会收到来自 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
我尝试在我的tsconfig.json 中使用exclude 键,但我找不到与所有__mocks__ 文件夹匹配的全局模式。
即"exclude":["**/__mocks__/*"] 从我的 dist 文件夹中删除根 __mocks__ 文件夹,但不删除任何子文件夹。
对于它的价值,我正在使用 Expo+React Native。我在package.json 中的 Jest 设置如下所示:
"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
}
【问题讨论】:
标签: typescript react-native jestjs expo