Chained cypress-testing-library commands don't work as expected
See original GitHub issuecypress-testing-library
version: 6.0.0node
version: 12.14.1npm
(oryarn
) version: yarn 1.21.1
Relevant code or config
cy.findAllByTestId('test-id').findByText('mytext').parents('.parent');
What you did: I want to chain commands from cypress-testing-library, so that they are executed in the same context. In the example above I want to retrieve the element which contains the text “mytext” but only for elements which have a parent (somewhere in the upper DOM) with a data-testid attribute with the value ‘test-id’.
What happened: The command doesn’t find an element with the given text, even if there would be such an element (proof is being provided in the Hint below).
Hint:
If I run the same code as above, but with a contains
instead of the findByText
everything works as expected:
cy.findAllByTestId('test-id').contains('mytext').parents('.parent');
Thanks for this library and the whole testing-library
family in general! Cheers!
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Error Messages | Cypress Documentation
This message means you tried to execute one or more Cypress commands outside of a currently running test. Cypress has to be able...
Read more >Cypress Testing Library
Cypress Testing Library extends Cypress's cy commands. ... You can now use all of DOM Testing Library 's findBy , findAllBy , queryBy...
Read more >cypress-testing-library - Bountysource
Chained cypress -testing-library commands don't work as expected $ 0. Created 2 years ago in testing-library/cypress-testing-library with 9 comments. cypress- ...
Read more >What is Cypress Testing Library and its Usage - BrowserStack
To query web elements, Cypress provides commands like get(), contains(), find() and within(). Using these commands, you further need to chain ...
Read more >Cypress Testing Library Intro - YouTube
This is a basic intro to Cypress Testing Library commands that you could use in your tests. It provides a new way to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s a bit unclear to me whether the chaining behaviour was removed on purpose (as I read @kentcdodds reply), or if it’s a bug (@NicholasBoll’s reply).
Personally, I think the chaining is useful. For example, say that in a table I want to verify that a particular cell (selected by the ‘rowheader’ role), has sibling cells with a certain expected content.
If you can’t chain I don’t see how I could gradually scope the selection of elements. For a practical example, see the screenshot below:
Let’s say I want to ensure that Job 1 (rowheader) is rendering with the expected type ‘Credentials expiry alert’. I’d expect to be able to do:
Yes, I could do this (and that works):
But that doesn’t guarantee that the expected cell is rendered in the row that contains the
Job 1
rowheader.Hi @silviuaavram,
I’m guessing your issue is related to the breaking change documented here: https://github.com/testing-library/cypress-testing-library/releases/tag/v6.0.0
Should be a reasonably easy update for you 😃