Unable to find the "window" object for the given node for input event
See original GitHub issue@testing-library/dom
version:7.28.1
- Testing Framework and version:
jest
7.0.14
- DOM Environment:
jsdom
16.4.0
Relevant code or config
import React from 'react';
import { createEvent, render } from '@testing-library/react';
describe('input', () => {
it('creates an event', () => {
const input: HTMLInputElement = render(<input />);
const event: React.FormEvent<HTMLInputElement> = createEvent.change(input, {})
});
});
What you did:
I ran the above test with npm test
(which runs jest
).
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
Reproduction repository: https://github.com/testing-library/dom-testing-library-template
Problem description:
Suggested solution:
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Jest Error: Unable to find the "window" object for the given node
As a first question before I can give you a more accurate answer, how do you have the jest environment configured?
Read more >Unable to find the "window" object for the given node for input ...
Unable to find the "window" object for the given node for input event.
Read more >dom-testing-library - npm
This will search for all elements with a placeholder attribute and find one that matches the given TextMatch . // <input placeholder="Username" ...
Read more >Window: error event - Web APIs - MDN Web Docs - Mozilla
The error event is fired on a Window object when a resource failed to load or couldn't be used — for example if...
Read more >DOM Standard
Returns the invocation target objects of event 's path (objects on which listeners will be invoked), except for any nodes in shadow trees...
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
To be clear, my suggestion is simply to change the error message from
to something like
and perhaps throw
TypeError
instead ofError
.The reason I mention that you’re already checking whether
node
is a DOM Node insidegetWindowFromNode
is because of:It literally says in the comment “node is a DOM node”.
I can definitely see how adding runtime type-checking to
fireEvent.change
itself could result in a more helpful error, but I agree on your comment about preferring static type checking and not having to maintain both.Thanks for the report.
We should check if we’re actually given an HTMLElement because that’s not the case here. What you probably wanted to do is