- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Jest 为我的 reactjs
项目进行单元测试。
当我想测试组件的渲染时,出现以下错误:
SyntaxError: /Users/jk/EpitechProjects/T-WEB-700/CountOfMoney_18/front/src/tests/components/Navbar.test.js:
Support for the experimental syntax 'jsx' isn't currently enabled (9:29):
7 |
8 | test('Navbar : should render navbar', ()=>{
> 9 | const wrapper = shallow(<Navbar />);
| ^
10 | expect(wrapper.find('nav').length).toBe(1);
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of
your Babel config to enable transformation. If you want to leave it as-is,
add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to
enable parsing.
但是,它似乎无法识别JSX
语法。
我已经尝试了 @babel/preset-react
和 @babel/plugin-syntax-jsx
建议,但仍然存在相同的错误。
这是我的一些配置文件:
jest.config.json
{
"setupFiles": [
"raf/polyfill",
"<rootDir>/src/setupTests.js"
],
"transform": {
"^.+\\.(js?)$": "babel-jest"
}
}
babel.config.js
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};
setupTests.js
//import '@testing-library/jest-dom';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({
adapter: new Adapter()
});
包.json
{
"name": "front",
"version": "0.1.0",
"private": true,
"dependencies": {
...
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/user-event": "^12.2.2",
...
"babel": "^6.23.0",
...
"react": "^17.0.1",
"react-dom": "^17.0.1",
...
"react-scripts": "4.0.0",
"react-test-renderer": "^17.0.1",
...
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"testJ": "jest --config=jest.config.json"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-syntax-jsx": "^7.12.1",
"@babel/preset-react": "^7.12.10",
"@testing-library/react": "^11.2.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"jest": "^26.6.3"
最佳答案
目前的罪魁祸首似乎是你的 babel.config.js
,你需要让它与 @babel/present-react
一起工作。所以更新如下:
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
['@babel/preset-react', {targets: {node: 'current'}}] // add this
]
};
关于reactjs - Babel 配置错误 : Support for the experimental syntax 'jsx' isn't currently enabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65248974/
使用 FFMPEG 将 flv 转换为 mp4 时,显示以下错误 [aac @ 0x2b4b640] The encoder 'aac' is experimental but experimenta
尝试在 IntelliJ 中构建 Kotlin/Ktor 应用程序时,出现多个表单警告 Warning:(276, 6) Kotlin: This class can only be used wit
我在 中编码C++ 在 Visual Studio (Windows 10)并收到此错误: #error The header providing std::experimental::filesy
我有一段代码使用了很多实验性的功能(when,smartmatch,given),这不是我的代码,并且我不想看到很多有关实验性功能的警告。因此,我在此代码中添加了no warnings 'experi
是否可以通过保留一个计数器来查看算法经过了多少次迭代来完成,或者是否需要记录持续时间? 最佳答案 目前接受的不会给你任何理论估计,除非你能以某种方式用一个近似它们的函数来拟合实验测量的时间。这个答案为
Kotlin 协程可以在生产中使用,它们的实验状态意味着什么? 最佳答案 更新:从 Kotlin 1.3 开始,Kotlin 协程不再是实验性的。 Kotlin 协程可以而且应该在生产环境中使用。这是
我正在使用Ubuntu 16.04。我有gcc-9.2.0,但是我在/usr/local/include/c++/9.2.0/experimental中找不到原子头文件,我想我在编译gcc时必须启用它
我想在 Android Studio 中根据口味设置我的 appName。我使用 com.android.tools.build:gradle-experimental:0.4.0 插件,所以我不能使
我想在我的 cpp 多线程代码中使用 std::experimental::barrier。但即使我写这样的代码: #include #include #include int main ()
我不是 100% 确定以下代码在语义上是正确的: #include #include int main() { std::string str = "lvalue string";
我正在尝试创建一个管道实现,该实现将公开一个接口(interface)以链接对某些给定数据的多个操作,同时保持所述数据的不变性。这里需要注意的是,操作(显然只是纯函数)应该能够改变数据的类型(例如,从
开发环境为 OS X 10.10.3, Perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thre
我试着做 github std::simd 上给出的例子但我的矢量化版本最终慢了 2-3 倍。如何正确使用? documentary缺乏认真的文档和进一步的示例用法。没有列出构造函数等。我确定我可能以
是否可以避免使用 @ExperimentalTime 注释我的代码的每一部分? ?环顾四周后,我在我的 gradle 构建中尝试了这个: withType().all { kotlinOpti
我正在尝试构建使用std::experimental::optional的项目。对于Linux,它可以很好地编译,但是对于android / ndk,编译器会抛出: error: no member
我的 Perl 程序抛出了一些警告,但我还没有在互联网上搜索解决方案。有什么方法可以重写以下代码片段,这样就不会抛出警告吗? “引用键是实验性的......”: foreach my $key ( k
我正在尝试使用 Cake-Plist 插件,但收到一个错误消息,指出动态尚未在正在使用的 Roslyn 版本中实现。然后从别人的建议中我被告知尝试 -Experimental 开关。使用开关时,我在尝
编译包含 的代码时出现错误. main.cpp 中的代码: #include int main() { } 编译这个(clang 版本是 3.9): clang++ main.cpp -o mai
我在 gcc 6.3.1 中使用实验性 std::filesystem 实现,遇到了一些关于 std::experimental::filesystem::directory_iterator #in
我使用 autobind-decorator bind 上下文到 this。 但是我得到了警告/错误 Experimental decorator usage(Decorators 是一个可能会改变的
我是一名优秀的程序员,十分优秀!