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

Use of queryByXXX vs getByXXX #53

Closed
simoncollins opened this issue Oct 29, 2019 · 5 comments
Closed

Use of queryByXXX vs getByXXX #53

simoncollins opened this issue Oct 29, 2019 · 5 comments

Comments

@simoncollins
Copy link

If you want to assert that an element exists and you have a page that loads slowly, you have to use queryByXXX selector variants, otherwise you will get intermittent failures using getByXXX when the element is not available in time.

I burnt a fair bit of time trying to figure out why I was getting intermittent failures because
I'm new to using testing-library and had forgotten that difference. I didn't initially make the connection that the error message I was seeing from getByText was because it was throwing an exception and not allowing Testcafe to retry the selector until the element was available.

Is it worth adding an example and/or notes about this usage distinction to the documentation? Currently they only show the usage of getByXXX selectors.

@benmonro
Copy link
Member

@simoncollins thank you for submitting this. I will definitely add a note about this to the docs as well as a link to the cheat sheet that breaks down when to use what query.

@simoncollins
Copy link
Author

Great, thanks @benmonro ... much appreciated, and thanks for the library!

@benmonro
Copy link
Member

benmonro commented Oct 29, 2019 via email

@simoncollins
Copy link
Author

simoncollins commented Oct 29, 2019

Sure, it was:

1) An error occurred in Selector code:

          Error: Unable to find an element with the text: Forgot your password?. This could be because the text is broken up
      by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more
      flexible.

Basically the app is quite sluggish to load at the moment and has a loading indicator before showing a login form with a link with the text Forgot your password? under it which I was using to detect that the form was shown successfully. So you intermittently get the message above followed by a dump of the DOM.

@benmonro
Copy link
Member

thanks @simoncollins. added notes in testing-library/testing-library-docs#313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants