" 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:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.