我开始学习React,当我做一些测试的时候我注意到了两个警告信息:
警告:ReactTestUtils已经迁移到react-dom/test-utils。更新引用以删除此警告。
警告:Shallow渲染器已经迁移到react-test-renderer/shallow。更新引用以删除此警告。
它们不会阻止测试运行或正确验证,但总是会出现这个错误。
看了文档后,我找到了这个页面,即使我包含了他们建议的那些代码行,警告消息仍然显示。
我正在尝试一个非常简单的测试,这是我的代码:
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);
})
})
我需要做什么才能解决这些警告?我已经将所有的软件包更新到最新版本了。