I'm writing tests for my React app using Jest and testing-library/react
My tests pass but I can't get rid of this error:
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.
I am also seeing multiple instances of this warning:
Warning: An update to ConnectFunction inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
Here are the imports at the top of my test suite:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { createMemoryHistory } from 'history';
//testing-library/react
import { render, fireEvent, waitForElement, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import {
wait
} from '@testing-library/dom';
import MyComponent from '../MyComponent';
Here's my package.json
"dependencies": {
"axios": "^0.18.1",
"react": "^16.11.0",
"react-dom": "^16.9.0",
"react-scripts": "2.1.5",
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.3",
"@testing-library/react": "^9.3.2",
}
react-dom
is already on v16.9. What am I missing?
Frustratingly, this error seems to appear intermittently. As I'm trying different things it will sometimes vanish entirely for a few runs of the test suite and then return.