React-testing-library: Problem testing modal on button click

Created on 3 Jan 2020  路  2Comments  路  Source: testing-library/react-testing-library

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.

Screen Shot 2020-01-03 at 11 52 05 PM

Here is the codesandbox link: https://codesandbox.io/s/wizardly-euler-xg7jh

Most helpful comment

Could you please post your fix?

All 2 comments

Got fix by making use of awaitElement & beforeAll()

Could you please post your fix?

Was this page helpful?
0 / 5 - 0 ratings