Niki18
Niki18

Reputation: 1

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 |     })

Upvotes: 0

Views: 1812

Answers (1)

Anthony Collin-Nadeau
Anthony Collin-Nadeau

Reputation: 129

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.

Upvotes: -1

Related Questions