Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactTestUtils has been moved

Tags:

I'm starting learning React and while I was doing some tests i noticed two warning messages:

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.

They don't prevent the tests from running nor from properly validating, but there is always this error.

By looking at the docs, I found this page, even after I included those lines they recommend, the warning message is still showing up.

I'm trying a very simple test to start with, this is my code:

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);     }) }) 

What do I need to do in order to solve this warnings? I already updated all my packaged to the latest versions.

like image 878
celsomtrindade Avatar asked Apr 11 '17 00:04

celsomtrindade


1 Answers

If you are using React 0.14 or React <15.5, in addition to enzyme, you will have to ensure that you also have the following npm modules installed if they were not already:

npm i --save-dev react-addons-test-utils react-dom 

If you are using React >=15.5, in addition to enzyme, you will have to ensure that you also have the following npm modules installed if they were not already:

npm i --save-dev react-test-renderer react-dom 
like image 109
pearpages Avatar answered Sep 17 '22 15:09

pearpages