Dom-testing-library: Unable to find the "window" object for the given node. fireEvent currently supports firing events on DOM nodes, document, and window. Please file an issue with the code

Created on 29 May 2019  路  3Comments  路  Source: testing-library/dom-testing-library

  • 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:

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:

// 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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ysgk picture ysgk  路  3Comments

JeffBaumgardt picture JeffBaumgardt  路  4Comments

Pau1fitz picture Pau1fitz  路  4Comments

nicolasschabram picture nicolasschabram  路  3Comments

kelly-tock picture kelly-tock  路  4Comments