cypress-testing-library: Testing library throws uncaught error

  • cypress-testing-library version: 9.0.0
  • node version: 18.12.1
  • npm (or yarn) version: 9.2.0

Relevant code or config

What you did: I am unable to run Cypress test after upgrading to Cypress version 12+ and @testing-library/cypress version 9.0.0 due to an uncaught error from the Cypress testing library.

An uncaught error was detected outside of a test
No commands were issued in this test.
The following error originated from your test code, not from Cypress.

> Cypress.Commands.addQuery() is used to create new queries, but findAllByLabelText is an existing Cypress command or query, or is reserved internally by Cypress.
If you want to override an existing command or query, use Cypress.Commands.overrideQuery() instead.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
[node_modules/@testing-library/cypress/dist/add-commands.js:8:1]
   6 |   command
   7 | }) => {
>  8 |   Cypress.Commands.addQuery(name, command);
     | ^
   9 | });
  10 | Cypress.Commands.add('configureCypressTestingLibrary', config => {
  11 |   (0, _.configure)(config); 

What happened:

image

Reproduction repository:

Problem description:

Suggested solution:

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 23

Most upvoted comments

I ran into this problem and the solution was to move import '@testing-library/cypress/add-commands' from my commands.ts file to my e2e.ts file.

I got this error as well but turns out I was importing twice import "@testing-library/cypress/add-commands"; Make sure you import only in cypress/support/commands.js

Ran into this too. It seems like a fault in the library to me. Why developer should need to care about a file having imports and exports (and potentially instantiating the library multiple times) is beyond me.

@vaclavGabriel thanks again for help, I finally got to the point… The problem was, as in your case, in export statement, however not in cypress/support/commands.js file, but in cypress/support/e2e.js. After I’ve removed that singe export statement, it got OK. I honestly think it’s a bug somewhere on the side of implementation of this lib.

My case solved.

I’m still seeing it after upgrade to cypress v.12.5 (latest atm) and @testing-library/cypress v9.0.0. I don’t use addQuery in my commands.js and still it fails to start tests. Would appreciate some help.

I finally fixed this. I’d been using Cypress.Commands.addQuery instead of Cypress.Commands.add

Thanks