Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs “如何修复”;SyntaxError:意外字符串“;运行测试时出错_Reactjs_Jestjs_Babel Jest - Fatal编程技术网

Reactjs “如何修复”;SyntaxError:意外字符串“;运行测试时出错

Reactjs “如何修复”;SyntaxError:意外字符串“;运行测试时出错,reactjs,jestjs,babel-jest,Reactjs,Jestjs,Babel Jest,我已经使用jest和酶为我的react应用程序开发了单元测试。我使用的是jest版本25.7.1。当我运行测试时,它失败了,错误如下。我不知道为什么它不喜欢导入关键字 src/components/App.test.tsx失败 ● 测试套件无法运行 D:\Dev\ps-visualizer\ClientApp\node_modules\@svgdotjs\svg.js\src\main.js:2 import './modules/optional/arrange.js' ^^^^

我已经使用jest和酶为我的react应用程序开发了单元测试。我使用的是jest版本25.7.1。当我运行测试时,它失败了,错误如下。我不知道为什么它不喜欢导入关键字

src/components/App.test.tsx失败 ● 测试套件无法运行

D:\Dev\ps-visualizer\ClientApp\node_modules\@svgdotjs\svg.js\src\main.js:2
import './modules/optional/arrange.js'
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
  at Object.<anonymous> (node_modules/@bentley/imodeljs-markup/lib/Markup.js:10:18)

我也遇到了这个问题,但主题是@uifabric/fluent。我发现的这个问题的另一个例子:
{
    "browser": true,
    "verbose": true,
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/src/setupTests.ts"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "globals": {
      "ts-jest": {
        "tsConfig": "tsconfig.test.json"
      }
    },
    "roots": [
      "<rootDir>/src"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
      "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
    ],
    "transform": {
      "^.+\\.jsx?$": "babel-jest",
      "^.+\\.tsx?$": "ts-jest"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "\\.(css|less|scss|json)$": "<rootDir>/__mocks__/styleMock.js",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  }
{
  "compilerOptions": {
    "target": "es2017",
    "lib": [
      "esnext.asynciterable",
      "es2017",
      "dom",
      "dom.iterable",
      "scripthost"
    ],
    "module": "commonjs",
    "stripInternal": false,
    "declaration": true,
    "strict": true, 
    "noImplicitAny": true, 
    "strictNullChecks": true, 
    "noImplicitThis": true,
    "alwaysStrict": true, 
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true, 
    "noFallthroughCasesInSwitch": false, 
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "declarationMap": true,
    "jsx": "react",
    "preserveConstEnums": true, 
    "forceConsistentCasingInFileNames": true
  }
}