-
Notifications
You must be signed in to change notification settings - Fork 470
Unable to find the "window" object for the given node for input event #863
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
Comments
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 -const input = render(<input />);
+const { getByRole } = render(<input />);
+const input = getByRole("textbox");
const event = createEvent.change(input, {}); |
That's right. Sorry. I'm always confusing |
@eps1lon If I understand the code correctly, you're already checking in I think the problem here is that the error message it a bit cryptic. It doesn't hint that the |
It doesn't seem that way.
Isn't that directly contradicting the statement you made above? The question is if we do want to extend runtime type-checking to |
To be clear, my suggestion is simply to change the error message from "Unable to find the "window" object for the given node ..." to something like `Expected node to be a DOM Node, but got ${getTypeName(node)}` and perhaps throw The reason I mention that you're already checking whether } else if (node.ownerDocument && node.ownerDocument.defaultView) {
// node is a DOM node
return node.ownerDocument.defaultView It literally says in the comment "node is a DOM node". I can definitely see how adding runtime type-checking to |
I don't have static type checking because I'm using JavaScript. Is TypeScript a requirement for dom-testing-library or am I misunderstanding what you mean? Also, this is a testing library. I'd argue that it's more important to have better error messages to make it easy for people understand and fix broken code or tests rather than disable the test because they're in a hurry and have absolutely not clue what's wrong. |
I had this error too but my issue was passing a function to fireEvent.click instead of a DOM node directly. -fireEvent.click(() => screen.getByText('Preview Book'));
+fireEvent.click(screen.getByText('Preview Book')); |
🎉 This fix is included in version 8.11.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@testing-library/dom
version:7.28.1
jest
7.0.14
jsdom
16.4.0
Relevant code or config
What you did:
I ran the above test with
npm test
(which runsjest
).What happened:
Reproduction repository:
https://github.com/testing-library/dom-testing-library-template
Problem description:
Suggested solution:
The text was updated successfully, but these errors were encountered: