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

"Please file an issue with the code that's causing you to see this error" #911

Closed
jdevries3133 opened this issue Mar 19, 2021 · 7 comments · Fixed by #949
Closed

"Please file an issue with the code that's causing you to see this error" #911

jdevries3133 opened this issue Mar 19, 2021 · 7 comments · Fixed by #949
Labels

Comments

@jdevries3133
Copy link

jdevries3133 commented Mar 19, 2021

Edit

Please see my last comment – this is a case of beginner's confusion but maybe a bit of a confusing error message as well.

  • @testing-library/dom version: 7.30.0
  • Testing Framework and version: @testing-library/react ^11.2.5
  • DOM Environment: jest / jestdom

Relevant code or config

https://github.com/jdevries3133/song_maker_gallery/blob/12fcc5be423a8cdac1a439e9e35d8e6ab1fe9bc9/django_smg/frontend/src/components/teacher/teacher.test.js#L44

What you did: Working on some tests; I am still very new to testing-library and unit testing with React overall.

What happened:

I got this error message, so am opening an issue as requested:

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: I got an error asking to open an issue.

Suggested solution: Who knows, but I hope this can help you trace down a bug if there is one. Let me know if you'd like any additional information.

@jdevries3133
Copy link
Author

Full traceback:

Screen Shot 2021-03-18 at 10 47 18 PM

@jdevries3133
Copy link
Author

Ok, so I am new and I think I was just making a mistake; I switched from

  fireEvent.click(screen, "addSpreadsheetButton");
  fireEvent.click(screen, "verifyGroupButton");

to

  fireEvent.click(screen.getByTestId("addSpreadsheetButton"));
  fireEvent.click(screen.getByTestId("verifyGroupButton"));

After doing that, the spooky error went away. Obviously, it couldn't find the element because I was passing in a string, not a node (duh). Still, I mindlessly submitted this issue after seeing the error message. I wonder if it is possible to provide a more descriptive error in cases like this?

@MatanBobi
Copy link
Member

Hi @jdevries3133, thanks for opening this :)
What would you think should be the error in that case?
The issue was that you passed in the screen object which is basically an object we create that contains all the queries attached to the document.body. That in fact really isn't a DOM node so it can't find the window attached to it.

@jdevries3133
Copy link
Author

Yes, the first part of the error is good and accurate, I just don't think it should solicit a GitHub issue since it's a case of user error. It made me think that I had caused an unexpected exception and uncovered a problem in the library when that obviously wasn't the case.

@MatanBobi
Copy link
Member

MatanBobi commented May 2, 2021

We can make a better error message here, maybe checking if the element is in fact an HTML element and only then ask the user to file an issue.
This function has some if statements already, I guess we can cover that case also.

function getWindowFromNode(node) {

@savcni01
Copy link
Contributor

savcni01 commented May 5, 2021

I plan to work on this issue today.

savcni01 added a commit to savcni01/dom-testing-library that referenced this issue May 5, 2021
 - first step for fix issue: Output User Error instead of New Issue error for wrong node from user
   getWindowFromNode(node) addresses issue testing-library#911
savcni01 added a commit to savcni01/dom-testing-library that referenced this issue May 5, 2021
…ror for wrong node from user

 - by adding additional check and correct error-message according to edge use case from the issue testing-library#911
@github-actions
Copy link

🎉 This issue has been resolved in version 7.31.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
Projects
None yet
3 participants