reactjs - 如何在 PhpStorm 中为 React 应用程序配置 Jest(create-react-app 风格)
问题描述
我正在尝试从 PhpStorm IDE 中运行测试。但是 IDE 抛出错误并且不接受我的配置为有效。虽然我将其配置为官方 PhpStorm 文档解释了它。
我有标准的 CRA 申请。我想使用 Enzyme 和 Jest 作为测试工具。
我使用jest-enzyme和jest-environment-enzyme包以及酶和酶适配器反应 16。
PhpStorm 文档说:
指定jest、react-scripts、react-script-ts、react-super-scripts或react-awesome-scripts包的位置。
我试图同时指定jest或react-scripts。并且这两个选项在 PhpStorm 中都不起作用。
这是我的两个配置:
No.1:开玩笑
IDE 抛出 SyntaxError 是因为它无法识别 React 组件。我认为它不知道如何使用 Babel 或 Webpack。但是 IDE 文档没有提到如何将 IDE 指向 Babel 或其他编译器。
No.2:反应脚本
IDE 抛出argv.config.match is not a function。它甚至无法开始测试。
jest-environment-enzyme要求我的jest.config.js如下:
module.exports = {
"setupFilesAfterEnv": ["jest-enzyme"],
"testEnvironment": "enzyme",
"verbose": true,
};
UPD1:
我的setupTests.js
文件:
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'jest-enzyme';
Enzyme.configure({
adapter: new Adapter()
});
解决方案
推荐阅读
- javascript - OpenLayers 地图上的可拖动图标
- sql - 从oracle中的日期列获取日期和时间
- android - 从屏幕上绘制图像但仍然从屏幕上获得点击事件
- mongodb - MongoDB | 使用数组进行图形查找
- php - 在 httpd 服务的 php 应用程序上启用 HTTPS
- php - PHP中的抽象方法和接口方法有什么区别?
- git - 在提交以保持历史干净之前,是否有必要将更改从 master 更改为分支
- angularjs - 为什么在 Angularjs 中使用组件?
- .net - 尝试删除已保存的 Excel 文件但收到 IOException:该进程无法访问该文件,因为它正被另一个进程使用
- java - 将图像上绘制的形状写入 PDF 文件时会反转