Skip to content

Chained cypress-testing-library commands don't work as expected #132

@dsumer

Description

@dsumer
  • cypress-testing-library version: 6.0.0
  • node version: 12.14.1
  • npm (or yarn) 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).

image

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');

image

Thanks for this library and the whole testing-library family in general! Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions