Refactoring tests written with ReactTestUtils
In the previous section, we learned how to convert tests written in Enzyme to React Testing Library. The process involved refactoring existing tests and then uninstalling the Enzyme library. In this section, we will use a similar process, only we will not have to uninstall an existing testing library. The ReactTestUtils
module is included with React, so we can simply not import the module in our test file when we don't want to use it. Since the refactoring process is similar to the previous section, we will only look at one example in this section. The test we will refactor verifies that a user can set an income amount:
import React from 'react'; import ReactDOM from 'react-dom'; import { act } from 'react-dom/test-utils'; import App from './App';
In the preceding code, we import React
, ReactDOM
, and the act
method. The act
method imported from the test-utils
module is used to sync component...