'Getting error Unable to find node on an unmounted component. react testing liberary?

I am using react testing library to unit test the component. but as soon as I am rendering the component I am getting the error.

Unable to find a node on an unmounted component. enter image description here

code:-

import React from 'react';
import {render, fireEvent, waitFor, screen} from '@testing-library/react';
import '@testing-library/jest-dom';
import {server} from '../__mocks__/server.mock';
import Deprovision from '../Deprovision';


beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

test('Deprovision renders correctly.', async () => {
    console.log(TEST_BASE_URL);
    render(<Deprovision
        onRef={() => {}}
        close={() => {}}
        updateDepID={() => {}}
    />);
});

the component does a lot of async calls on init and then updates the state on the component.

but it seems that the test is removing the component before the async calls have a chance to update the state.

this works for the basic component without async calls.

what am I missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source