Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

" Unable to find the "window" object for the given node." when node is a Promise #609

Closed
JoshuaKGoldberg opened this issue Jun 7, 2020 · 6 comments · Fixed by #646
Closed
Labels
enhancement New feature or request help wanted Extra attention is needed released

Comments

@JoshuaKGoldberg
Copy link
Contributor

  • @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.

@zzzachzzz
Copy link

zzzachzzz commented Jun 13, 2020

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. 😅

@kentcdodds
Copy link
Member

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 😉

@kentcdodds
Copy link
Member

This is an invitation to make a pull request 😁

@kentcdodds kentcdodds added enhancement New feature or request help wanted Extra attention is needed labels Jun 13, 2020
@timdeschryver
Copy link
Member

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.

@kentcdodds
Copy link
Member

That would definitely be cool

@nickserv nickserv linked a pull request Jun 15, 2020 that will close this issue
4 tasks
kentcdodds pushed a commit that referenced this issue Jun 15, 2020
…Node (#646)

* Added explicit error message for Promises passed to getWindowFromNode

* Applied suggestion

Closes #609
@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 7.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants