Questions tagged «babel-jest»

7
Jest是否支持ES6导入/导出?
如果我import/export从ES6使用,那么我所有的Jest测试都会失败并显示以下错误: 意外的保留字 我将受测对象转换为使用旧式IIFE语法,然后突然我的测试通过了。或者,采用一个更简单的测试用例: var Validation = require('../src/components/validation/validation'); // PASS //import * as Validation from '../src/components/validation/validation' // FAIL 同样的错误。显然这里的导入/导出有问题。为了使测试框架满意,使用ES5语法重写代码对我来说是不切实际的。 我有通天的笑话。我尝试了来自GitHub问题的各种建议。到目前为止没有走。 文件package.json "scripts": { "start": "webpack-dev-server", "test": "jest" }, "jest": { "testPathDirs": [ "__tests__" ], "testPathIgnorePatterns": [ "/node_modules/" ], "testFileExtensions": ["es6", "js"], "moduleFileExtensions": ["js", "json", "es6"] }, 文件babelrc { "presets": ["es2015", "react"], …

5
如何解决“无法在模块外部使用导入语句”
我有一个使用TypeScript,Jest,Webpack和Babel构建的React应用程序(不使用Create React App)。尝试运行“ yarn jest”时,出现以下错误: 我尝试删除所有软件包并重新添加它们。它不能解决此问题。我看过类似的问题和文档,但仍然有些误解。我什至遵循了另一本从头开始设置此环境的指南,但我的代码仍然收到此问题。 依赖项包括... "dependencies": { "@babel/plugin-transform-runtime": "^7.6.2", "@babel/polyfill": "^7.6.0", "babel-jest": "^24.9.0", "react": "^16.8.6", "react-dom": "^16.8.6", "react-test-renderer": "^16.11.0", "source-map-loader": "^0.2.4" }, "devDependencies": { "@babel/core": "^7.6.0", "@babel/preset-env": "^7.6.0", "@babel/preset-react": "^7.0.0", "@types/enzyme": "^3.9.2", "@types/enzyme-adapter-react-16": "^1.0.5", "@types/jest": "^24.0.13", 组件的导入行... import * as React from "react"; import { BrowserRouter as Router, …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.