Dom-testing-library: " Unable to find the "window" object for the given node." when node is a Promise

Created on 7 Jun 2020  路  6Comments  路  Source: testing-library/dom-testing-library

  • @testing-library/dom version: 7.10.1
  • Testing Framework and version: jest@26.0.1 via @testing-library/react@10.2.1
  • DOM Environment: Jest defaults

Relevant code or config

fireEvent.click(new Promise(jest.fn());

What you did:

This is a contrived example; what I actually did was pass the result of findByRole instead of getByRole.

What happened:

 Unable to find the "window" object for the given node. Please file an issue with the code that's causing you to see this error: https://github.com/testing-library/dom-testing-library/issues/new

      40 |       await act(async () => {
    > 41 |         fireEvent.click(jest.fn());
         |                   ^
      42 |       });

Problem description:

getWindowFromNode doesn't account for the node not being a Node.

Suggested solution:

Give an explicit error message if it's an instance of a Promise.

enhancement help wanted released

Most helpful comment

This is an invitation to make a pull request 馃榿

All 6 comments

Yep, I had the same exact issue the other day where I tried to fireEvent.click(screen.findBy*(...)) instead of fireEvent.click(screen.getBy*(...)), completely by accident. It took me way too long to figure out the problem. :sweat_smile:

I'm good with this. Let's just check if it has a .then function and if it does we can give a helpful error message.

Though you may want to use typescript to avoid this 馃槈

This is an invitation to make a pull request 馃榿

I think we could add this to the eslint repo.
If I recall correctly we already have some helpers to find a Promise, so this should be not too hard to do.

That would definitely be cool

:tada: This issue has been resolved in version 7.15.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

icfantv picture icfantv  路  4Comments

ricardozv28 picture ricardozv28  路  3Comments

JeffBaumgardt picture JeffBaumgardt  路  4Comments

ruscal picture ruscal  路  3Comments

nicolasschabram picture nicolasschabram  路  3Comments