Skip to content
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

Configuration to control the suggestions for the findByRole command #277

Open
srkrish opened this issue Jun 11, 2024 · 1 comment
Open

Comments

@srkrish
Copy link

srkrish commented Jun 11, 2024

  • cypress-testing-library version: 10.0.1
  • node version: v18.15.0
  • npm (or yarn) version: 9.5.0

What you did:

Used cy.findByRole and cy.findAllByRole predominantly in my project

What happened:

When the command fails to find an accessible role, it lists all the accessible roles on the page after the term "Here are the accessible roles:"

Problem description:

Well, the suggestions are kind of agreeable when we run locally, but on a CI machine, they become really verbose. If the page has multiple accessible elements, it lists numerous options that span more than 1000 lines, making it pretty difficult to scroll and imagine this happening for multiple tests. Tried the following solution

cypress\support\e2e.js:

import { configure } from '@testing-library/cypress';

configure({
throwSuggestions: false,
computedStyleSupportsPseudoElements: false,
});

Suggested solution:

How to get the configuration working?

@joelindridge-sh
Copy link

Hi @srkrish, I too struggled with the verbose dom output. Couldn't get DEBUG_PRINT_LIMIT to work.

Stumbled across this which suggests using getElementError to configure the error that's returned.

Not sure if this is quite what you're looking for but this should suppress the error output:

(cypress\support\e2e.js:)

import { configure } from "@testing-library/cypress";

configure({
  getElementError: () => null,
});

Or you could limit to just the first so many characters:

configure({
  getElementError(message) {
    const error = new Error(message.slice(0, 100));
    error.name = "TestingLibraryElementError";
    error.stack = null;
    return error;
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants