- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始学习 React,在做一些测试时我注意到两条警告消息:
Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning.
它们不会阻止测试运行或正确验证,但总是存在此错误。
通过查看文档,我 found this page ,即使在我添加了他们推荐的那些行之后,警告消息仍然显示。
我正在尝试一个非常简单的测试,这是我的代码:
import React from "react";
import toJson from "enzyme-to-json";
import { shallow } from "enzyme";
import { About } from "./About";
describe('Rendering test', () => {
const component = shallow(<About />);
const tree = toJson(component);
it('Should render the About component', () => {
expect(tree).toMatchSnapshot();
})
it('Should not contain an h2 element', () => {
expect( component.contains('h2') ).toBe(false);
})
})
我需要做什么才能解决此警告?我已经将所有打包更新到最新版本。
最佳答案
如果您使用的是 React 0.14 或 React <15.5,除了 enzyme 之外,您还必须确保还安装了以下 npm 模块(如果尚未安装):
npm i --save-dev react-addons-test-utils react-dom
如果您使用的是 React >=15.5,除了 enzyme 之外,您还必须确保还安装了以下 npm 模块(如果尚未安装):
npm i --save-dev react-test-renderer react-dom
关于reactjs - ReactTestUtils 已被移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43334942/
我开始学习 React,在做一些测试时我注意到两条警告消息: Warning: ReactTestUtils has been moved to react-dom/test-utils. Updat
我得到了一些意想不到的 ReactTestUtils 测试结果。这是代码: 来源: var React = require('react'); module.exports = React.creat
在reactjs docs对于模拟: Simulate has a method for every event that React understands. 我对 ReactJS 还很陌生,所以我
例子如下: http://jsfiddle.net/hulufei/twr4thuh/7/ 它只是在虚拟 dom 中绑定(bind) onClick 时起作用(如第 18 行),但是如果我注释掉第 1
我在 React 表单中有一个 HTML5 文件类型输入,类似于以下内容 文件上传后,this.onChange 访问所选文件,验证它们并转换表单。 我试图弄清楚如何使用 ReactTestUtil
下面这段代码是用 typescript 写的,它使用了“react-dom/test-utils”中的 ReactTestUtils。 let nameInput = TestUtilsExtende
用于 react 测试的 enzyme 、ReactTestUtils和react-testing-library之间有什么区别? ReactTestUtils 文档说: ReactTestUtils
尝试使用 Karma+Jasmine 测试 React 组件,我正在尝试检查是否调用了 onClick 处理程序中的所有函数,但测试返回错误结果: `Expected spy reportLoginW
我正在尝试使用 ReactTestUtils 为 React Native 项目设置单元测试但是,我在运行 npm test 时收到此错误: Cannot find module 'react/lib
我正在尝试测试呈现 iframe 并将标记直接注入(inject)该 iframe 的 React 组件。 (我没有尝试在 iframe 中加载 URL。) 该组件实际上在浏览器中工作得很好,但到目前
我在我的测试中渲染了一个组件: component = TestUtils.renderIntoDocument( foo foo foo ); $bodyElem
我有一个 React 项目,正在尝试设置一些测试 由于以下设置指南/问题: https://github.com/facebook/jest/issues/1353 , https://github.
我是一名优秀的程序员,十分优秀!