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
querySelectorAll is not a function when being called by getByTestId #537
Comments
Hey @Nubzor, Thanks for the kind words. Based on your example it seems like you didn't deconstruct const { getByTestId } = render(Loader);
// Some action here that will cause the spinner to be displayed.
expect(getByTestId('spinner')).toBeVisible(); That should resolve it for you :) Side recommendation for structural tests you can use snapshots in Jest, makes life much easier so your main tests can focus on the UX and not brittle unit tests. const { container } = render(Loader);
expect(container).toMatchSnapshot(); |
We could probably typecheck the 1st arg to throw a more specific error case in this case |
@mihar-22 that was exactly the case. When I used the getByTestId function the VisualStudio Code has automatically added the import statement from Also, thank you for the side recommendation I definitely find it useful - I am on my first private project using Svelte so I am trying different solutions and approaches to get used to the library. Thank you. PS. I agree with Alex, type check could be helpful for future devs facing the same problem I had. |
I like the idea @alexkrolick but how would we go about this? Maybe a one-time warning? Some people might actually need to import these functions for other use cases. Another idea could be we don't export it from this library at all, and when required you'd use the DOM testing library directly. It'd also stop editors from automatically importing it and causing any confusion. What do you think? |
Just warn when the function is called with a first argument that isn't a DOM node. It will fail anyways with a confusing error We would probably want to do this at the DOM Testing Lib level, although there could be other things added on for framework wrappers. Removing the render-result binding in favor of screen would be a big breaking change so we might not want to do that for a while. |
Hi, I'd like to work on this issue. If I understood correctly, the goal is to have all of the base queries throw an error warning that the first argument of a base query must be a DOM node. Which includes the following queries and its variants:
Is this what is intended? |
Every query is built on top of the Thanks! |
To be clear, these days we're encouraging people to use |
Thank you for the tip!
Yes, I'm aware. But thank you for calling it to my attention :) I'll get to work then! |
This is intended to give an informative warning when a base-query is called with a container that's neitheir an Element, Document or DocumentFragment. Ref: testing-library#537
This is intended to give an informative warning when a base-query is called with a container that's neitheir an Element, Document or DocumentFragment. Ref: testing-library#537
🎉 This issue has been resolved in version 7.10.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This is intended to give an informative warning when a base-query is called with a container that's neitheir an Element, Document or DocumentFragment. Closes: testing-library/dom-testing-library#537
In the beginning, I would like to thank you for the time you folks put to develop and maintain the library.
I face an issue related to missing .querySelectorAll function while calling getByTestId method which is odd because when I check the object property then I can see that the function exists 🤷
Code example:
Output:
There is a list of dependencies and their versions:
Node: 12.16.1 on Windows 10
I am not sure whether this is a bug or I missed something during the configuration, any tips would be appreciated.
Greetings,
Mateusz
The text was updated successfully, but these errors were encountered: