I have a test that uses Jest and react-testing-library with a .tsx test file (TypeScript):
import React from "react";
import { Provider } from 'react-redux';
import { render, screen } from "@testing-library/react";
import Home from "./Home";
describe('Home', () => {
test("renders Programs without crashing", async () => {
const storeFake = (state: any) => ({
default: () => { },
subscribe: () => { },
dispatch: () => { },
getState: () => ({ ...state })
});
const store = storeFake({}) as any;
const { getByAltText } = render(<Provider store={store}>
<Home />
</Provider>);
// render should show the title
expect(getByAltText(/Great State/)).toBeInTheDocument();
});
The test passes but an exception is thrown:
console.error node_modules/react-dom/cjs/react-dom.development.js:88
Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.
in video (at Home.tsx:10)
in div (at Home.tsx:9)
in Home (created by ConnectFunction)
in ConnectFunction (at Home.test.tsx:15)
in Provider (at Home.test.tsx:14)
First, does anyone know how to resovle the exception. Second, I know this is a warning but it seems pretty serious, shouldn't the test fail?