我有一个React组件,例如 A (Javascirpt, .jsx ),在 A 内,我渲染了另一个组件< strong> B (Typescript, .tsx )。每当我进行笑话测试时,都会收到错误消息:
Cannot find module '../B' from 'A.js'
当B是Javascript模块时,它运行良好。
我的笑话配置如下:
{
"setupFiles": [
"./test/jest/index.js"
],
"snapshotSerializers": [
"../../node_modules/enzyme-to-json/serializer"
],
"transform": {
"^.+\\.js$": "../../node_modules/babel-jest",
"^.+\\.html$": "./test/jest/transformers/jest.ejx-transformer.js"
},
"modulePaths": [
"test",
"<rootDir>/src/",
"<rootDir>/",
"<rootDir>/../",
],
"roots": [
"<rootDir>",
"<rootDir>/../../node_modules/",
],
"moduleNameMapper": {
"\\.scss$": "identity-obj-proxy",
"\\.tsx$": "identity-obj-proxy",
"\\.svg$": "emptyModuleStub",
"\\.png": "emptyModuleStub",
"\\.jpg": "emptyModuleStub",
"\\.css$": "emptyModuleStub",
"\\.less$": "emptyModuleStub",
"\\.png$": "emptyModuleStub",
"\\.jpg$": "emptyModuleStub",
"withStyles$": "withStyleStub",
"getAppConfig.__PROCESS_ENV__$": "liteAppConfigStub",
"react-color$": "emptyModuleStub",
"lodash-dep": "<rootDir>/src/libs/lodash.compat",
"lodashDep$": "lodash",
"jst!(.*)": "$1",
"text!(.*)": "$1",
"rule-engine\/(.*)": "emptyModuleStub",
"app/modules/insights/plugins": "emptyModuleStub",
"jqUtils": "<rootDir>/src/libs/plugins/jquery.utils",
"jquery.slider": "<rootDir>/src/libs/plugins/jquery.slider",
"jqContextualDialog": "<rootDir>/src/libs/plugins/jquery.contextualDialog",
"jqSelect2": "<rootDir>/src/libs/plugins/select2",
"jquery.ui": "<rootDir>/src/libs/plugins/jquery-ui",
"jquery.imagesLoaded": "<rootDir>/src/libs/plugins/jquery.imagesLoaded",
"backbone": "<rootDir>/src/libs/backbone",
"typeahead": "<rootDir>/src/libs/typeahead",
"bootstrap-dep": "<rootDir>/src/libs/bootstrap/bootstrap",
"marionette": "<rootDir>/src/libs/backbone.marionette",
"propertyParser": "<rootDir>/src/libs/plugins/propertyParser",
"^.*-loader.*!(?!\\.)(.*)": "$1",
"^.*-loader.*!\\.(?=\/)(.*)": ".$1"
},
"testMatch": [
"**/__tests__/**/*.spec.js?(x)|**/?(*.)spec.js?(x)"
],
"testURL": "https://localhost/",
"watchman": false
}
我的打字稿配置是:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"strictNullChecks": true,
"module": "es6",
"jsx": "react",
"target": "es6",
"allowJs": true,
"noEmitOnError": true
},
"awesomeTypescriptLoaderOptions": {
"useBabel": true,
"useCache": true
},
"include": [
"../src/",
"./global.d.ts"
]
}