我正在尝试测试一些使用react-bootstrap的React组件。
由于某种原因导入来自react-bootstrap的组件将失败,并显示以下错误:
FAIL test\App.test.js
● Test suite failed to run
C:\Users\AbfalterJakob\Documents\projects\koreanbuildsoverwolf2\node_modules\react-bootstrap\es\DropdownButton.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
^^^^^^
SyntaxError: Unexpected token import
2 | import React from "react";
3 | import "./LoginComponent.css";
> 4 | import DropdownButton from "react-bootstrap/es/DropdownButton";
5 | import MenuItem from "react-bootstrap/es/MenuItem";
6 | import BackendFactory from "../../util/BackendFactory";
7 | import GlobalState from "../../GlobalState";
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.<anonymous> (src/components/subcomponents/LoginComponent.jsx:4:23)
at Object.<anonymous> (src/components/IndexComponent.jsx:6:23)
我尝试使用mocha和jest两者都会导致相同的错误消息。
我的Jest配置是:
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/test/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/test/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"mjs",
"js",
"json",
"web.jsx",
"jsx",
"node"
]
答案 0 :(得分:0)
尝试添加jest.disableAutomock();