I have a log-in button in my component and on that button click I need to write a test case to check if the modal box with data-testid=login is present in the document
This is my code
const {getByTestId} = render(<NonLoggedIn /> );
const container = document.body;
fireEvent.click(getByTestId('btnHeaderLogin'));
await wait(() => {
const htmlElement = document.querySelector('[data-testid="loginform"]');
expect(htmlElement).toBeInTheDocument();
});
`
Attached screenshot of the error.

Here is the codesandbox link: https://codesandbox.io/s/wizardly-euler-xg7jh
Got fix by making use of awaitElement & beforeAll()
Could you please post your fix?
Most helpful comment
Could you please post your fix?