-
Notifications
You must be signed in to change notification settings - Fork 153
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
TypeError: container.querySelectorAll is not a function #109
Comments
I think this is the same issue that was brought up here: #100 (comment) Thank you for opening it so we can discuss this. cc @tlrobinson and @twgraham. When I merged that other PR I didn't realize it was going to break this use case. I personally like this style quite a bit and would like it very much if we could get the benefits that #100 was going for without losing the ability to write tests in this way. If we cannot, then I think we should revert #100. Anyone have ideas? |
I'd also love feedback from @NicholasBoll on this as well. |
Thanks for the quick response on this @kentcdodds! |
Just to be clear, the justification for the style I prefer is based on how describe('anonymous calculator', () => {
it('can make calculations', () => {
cy.visit('/')
.get('.one')
.click()
.get('.plus')
.click()
.get('.two')
.click()
.get('.equals')
.click()
.get('.total')
.should('have.text', '3')
})
}) I really like that style and want to make sure we preserve that style for our queries. I think that is least surprising for people. |
However, this isn't how The way Cypress recommends "reseting" to the root element is with IMHO the ability to chain commands is more important than supporting the above style, which isn't really idiomatic Cypress. IMHO this is much more readable: cy.visit('/')
cy.get('.one').click()
cy.get('.plus').click()
cy.get('.two').click()
cy.get('.equals').click()
cy.get('.total').should('have.text', '3') |
@kentcdodds I think the comment i made in #100 would only apply to 5.1.0, this is 5.0.2 so it could be a different issue? 🤷♂️ |
Oh, that's true. Maybe it is a different issue. Anyone want to dig in and figure out where the problem lies? |
Scratch that... It could be resolving the next minor version (5.1.0) because the package.json requires ^5.0.2. Probably the same issue 😅 |
Oh, Crumbs. No, I was on 5.1.1, I'm sorry @kentcdodds @twgraham! |
Your call - I can see the benefits of sticking to the old way, and the new way which @tlrobinson has provided. I don't think you can have it both ways though (from a usability perspective). It would become confusing (magic?) how the command resolves elements. I would also suggest that adding it as an option is a bad idea e.g. findByText(..., { usePrevious: true }) Pick a method and stick with it 👍 |
Ok, I think that in order to address the breaking change I'm going to revert #100 right now, and then we can talk about the merits of making a breaking change to support it in a new major version bump. |
5.1.2 has been published to revert that change. I apologize for not recognizing the implications of the change in the first place. Sorry for the bump. |
* Fixes testing-library#109 without breaking change caused by testing-library#100
* feat: add more helpful debugging information to queries * Add element selector information for debugging (outlines element when you click on command) (fixes #103) * Add @testing-library/dom errors (from `get*` queries) to failure messages - these are more helpful than the generic `find*('input') does not exist` messages (fixes #103) * Add retryability to `findBy*` when multiple elements are found (fixes #83) * Add option to disable logging of all commands * `query*` and `find*` have a consistent code path and error messaging (fixes #103) * Remove usage of Cypress commands in queries (fixes #103) * feat: add ability for queries to inherit previous subject * Fixes #109 without breaking change caused by #100 * feat: add parent/child log type detection * chore: implement feedback * docs: update readme to complete my thought process * slightly simplify config fn * Update README.md Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com> Closes #103, Closes #109, Closes #110
🎉 This issue has been resolved in version 5.2.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
For people who came across this issue, from what I understand, starting from cy.visit('/')
cy.findByText(/^1$/).click()
cy.findByText(/^\+$/).click()
cy.findByText(/^2$/).click()
cy.findByText(/^=$/).click()
cy.findByTestId('total').should('have.text', '3') More discussion about this decision on: #110 @kentcdodds @tlrobinson please correct me if I'm wrong. Also, it would be helpful to add this change to release changelog: https://github.com/testing-library/cypress-testing-library/releases. |
Hi @ayush000, It was included 😁 |
ahh! Missed it. |
Hi all, regarding https://testingjavascript.com/lessons/cypress-installing-cypress-testing-library, I tried to not add cy.visit('/')
cy.findByText(/^1$/).click()
cy.findByText(/^\+$/).click()
cy.findByText(/^2$/).click()
cy.findByText(/^=$/).click()
cy.findAllByText(/^3$/).should('have.length', 2) or we could sacrifice smallest addends and have no ambiguity, for example cy.findByText(/^5$/).click()
cy.findByText(/^\+$/).click()
cy.findByText(/^6$/).click()
cy.findByText(/^=$/).click()
cy.findByText(/^11$/).should('be.visible') I'm currently learning from the course in real time (wonderful course btw), so if there are better ways, please @ me 👋 |
I agree that would be better for the course. Will probably do something like that in the next update 👍 thanks! |
cypress-testing-library
version: 5.1.1node
version: 12.4.0npm
(oryarn
) version: 1.21.1 (yarn)Relevant code or config
What you did: Attempted to run tjs/cypress-04 branch of https://github.com/kentcdodds/jest-cypress-react-babel-webpack/tree/tjs/cypress-04
What happened:
Reproduction repository:
https://github.com/kentcdodds/jest-cypress-react-babel-webpack/tree/tjs/cypress-04
Problem description:
TypeError: container.querySelectorAll is not a function
Suggested solution:
--
The text was updated successfully, but these errors were encountered: