'Cannot read property 'tagName' of null error in react testing library with jest
I am writing test cases using react testing library with jest. i want to check dropdown list of another Multiselect to be present when i select from first dropdown.
import user from '@testing-library/user-event'
TypeError: Cannot read property 'tagName' of null
101 | const { getByText, container } = render(<Product />)
102 | const actionDiv = container.querySelector('#option-0')
> 103 | user.click(actionDiv)
| ^
104 | await act(async () => {
105 | await waitFor(() => expect(getByText(/10.or/i)).toBeInTheDocument())
106 | })
Solution 1:[1]
You should avoid to use container to query elements like it said here.
Use queries like you did in your expect function.
You have alot of those to help you here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anthony Collin-Nadeau |
