question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I have problem when I am using Cypress Testing Library

See original GitHub issue

Current behavior

TypeError: cy.findByRole is not a function

Desired behavior

I am getting this error even I am using the cypress testing library as in the docs I have added this line to project cypress/support/commands.js: import@testing-library/cypress/add-commands’;

And in my test, I use it like this

describe("App", () => {
  it("user can fetch stories", () => {
    cy.visit("http://localhost:3000/");
    
    cy.findByRole("button", { name: /fetch stories/i }).click();
  });
});

then when I run the test I get this error `TypeError: cy.findByRole is not a function

Test code to reproduce

describe("App", () => {
  it("user can fetch stories", () => {
    cy.visit("http://localhost:3000/");
    
    cy.findByRole("button", { name: /fetch stories/i }).click();
  });
});

Cypress Version

9.1.1

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

13reactions
ahmedelaminecommented, Dec 6, 2021

I fix it, by adding an index.js file in cypress/support/

// cypress/support/index.js

import "./commands";
4reactions
zeyasarcommented, Jul 21, 2022

@np185092 I fixed the problem by adding the "import ‘@testing-library/cypress/add-commands’ line to the cypress/support/command.ts " file

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress Testing Library
Examples​ Cypress Testing Library supports both jQuery elements and DOM nodes. This is necessary because Cypress uses jQuery elements, while ...
Read more >
Best Practices - Cypress Documentation
We use Testing Library internally, and our philosophy aligns closely with Testing Library's ethos and approach to writing tests. We strongly endorse their...
Read more >
Using testing-library findby* queries with @badeball/cypress ...
I have a react app that I'm trying to test with Cypress using the badeball/cypress-cucumber-preprocessor and testing-library but I'm getting ...
Read more >
@testing-library/cypress - npm
The problem. You want to use DOM Testing Library methods in your Cypress tests. This solution. This allows you to use all the...
Read more >
Which query to use? - Mattermost Developers
With that, which query should I use when writing Cypress tests? ... Do you still have problems knowing how to use Testing Library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found