testing-library / cypress-testing-library

🐅 Simple and complete custom Cypress commands and utilities that encourage good testing practices.
http://npm.im/@testing-library/cypress
MIT License
1.8k stars 152 forks source link

get/query variants don't exist #250

Closed jamesarosen closed 9 months ago

jamesarosen commented 1 year ago

The issue template says that questions about query APIs should go to https://github.com/kentcdodds/dom-testing-library, but these methods do exist there: https://github.com/testing-library/dom-testing-library/blob/0ce0c7054dfa64d1cd65053790246aed151bda9d/types/queries.d.ts#L297-L302

The Cypress Testing Library docs say

You can now use all of DOM Testing Library's findBy, findAllBy, queryBy and queryAllBy commands off the global cy object.

Those same docs reference "all library definitions". That file includes only findBy… and findAllBy… methods. cy.queryAllByTestId, for example, doesn't exist.

Why I care

I want to look for [data-testid="foo"] -- which may or may not exist -- then make a decision based on what I get back. I want to wait for the standard timeout to make sure the element doesn't exist, so I don't want to just use document.querySelector.

jamesarosen commented 1 year ago

I think this is expected behavior given the README:

query* queries are not supported. You should use the should('not.exist') assertion instead to check for the absence of an element.

get queries are not supported. find queries do not use the Promise API of DOM Testing Library, but instead forward to the get queries and use Cypress' built-in retryability using error messages from get APIs to forward as error messages if a query fails.

I think this is an issue with the Cypress Testing Library docs.

vadimshvetsov commented 9 months ago

Lost some time to realising this as well, opened pull request for that: https://github.com/testing-library/testing-library-docs/pull/1344

MatanBobi commented 9 months ago

Thanks to @vadimshvetsov this is now properly documented. I'm closing this one as it was a documentation issue, these queries aren't meant to be supported.