question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • @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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kentcdoddscommented, Jun 13, 2020

This is an invitation to make a pull request 😁

1reaction
timdeschryvercommented, Jun 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Error: Unable to find the "window" object for the given ...
As a first question before I can give you a more accurate answer, how do you have the jest environment configured?
Read more >
Common mistakes with React Testing Library
Hi there I created React Testing Library because I wasn't satisfied with the testing landscape at the time. It expanded to DOM Testing ......
Read more >
dom-testing-library
The dom-testing-library is a very light-weight solution for testing DOM nodes (whether simulated with JSDOM as provided by default with jest or ...
Read more >
Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of already ...
Read more >
How to solve "window is not defined" errors in React and ...
Because in the Node.js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found