Skip to content

cypress cannot find the line number of failed .findBy commands #232

Closed
@rmmanseau

Description

@rmmanseau

first, to address this:

HI! PLEASE STOP TO READ THIS!! If your issue is regarding one of the query
APIs (`getByText`, `getByLabelText`, etc), then please file it on the
https://github.com/kentcdodds/dom-testing-library repository instead. If you
file it here it will be closed. Thanks :)

the getBy functions do work properly, but when they fail cypress is not able to figure out where the failure is coming from & point to it accurately. This makes for difficult debugging because it's not possible to immediately jump to the failed testing library commands. I believe that this issue does belong here, as the issue is specific to integration with cypress test runner.

  • cypress-testing-library version: 8.0.3
  • cypress version: 10.10.0
  • node version: 14.20
  • npm (or yarn) version: 1.22.19

Relevant code or config

describe('does not show failing assertion', () => {
  it('cy.findByText', () => {
    cy.mount(<App/>);
    cy.findByText(TEXT); // <---- cypress cannot tell that this line is the point of failure
  })

  it('cy.findByTestId', () => {
    cy.mount(<App/>);
    cy.findByTestId("code");
    cy.findByTestId("yeet"); // <---- cypress cannot tell that this line is the point of failure 
  })
})

What you did:

run a test that fails on a cy.findBy* command

What happened:

it creates a TestingLibraryElementError and dumps the entire state of the DOM

image

What I expected:

it generates an Assertion Error and points to the line of the failing assertion.

image

Reproduction repository: https://github.com/rmmanseau/cy-testing-library-repro

Problem description:

@testing-library/cypress doesn't generate the correct assertion type / stack trace / whatever is required by cypress in order for it to point to the location of the failing line.

Suggested solution:

do the thing that cypress expects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions