dom-testing-library version:node version:npm (or yarn) version:Relevant code or config
What you did:
What happened:
Reproduction repository: https://github.com/alexkrolick/dom-testing-library-template
Problem description:
Suggested solution:
Faced a similar issue. Ensure that you are querying the element correctly. For example if you are using getAllByText, it returns an array instead of the element object itself. In which case, do:
// Case 1: Fail
const button = getAllByText(container, 'Send')
fireEvent.click(button) // Unable to find the "window" object for the given node. fireEvent currently supports firing events on DOM nodes, document, and window....
// Case 2a: Success
const button = getAllByText(container, 'Send')
fireEvent.click(button[0]) // OK
// Case 2b: Success
// or simply just change the query instead
const button = getByText(container, 'Send')
fireEvent.click(button) // OK
In my case:
const buttonSubmit = screen.findByText('submit');
fireEvent.click(buttonSubmit); // fail
const buttonSubmit = screen.getByText('submit');
fireEvent.click(buttonSubmit); // OK
@GTOsss, findByText returns a promise which should be await-ed.
Most helpful comment
Faced a similar issue. Ensure that you are querying the element correctly. For example if you are using
getAllByText, it returns an array instead of the element object itself. In which case, do: