testing-library / cypress-testing-library

🐅 Simple and complete custom Cypress commands and utilities that encourage good testing practices.
http://npm.im/@testing-library/cypress
MIT License
1.8k stars 152 forks source link

Doesn't work with Cypress 13.4.0 due to `addQuery` usage #268

Open brycefranzen opened 9 months ago

brycefranzen commented 9 months ago

Relevant code or config:

https://github.com/testing-library/cypress-testing-library/blob/0f2f002907d61712de8f46e9a4115cfb12e58eec/src/add-commands.js#L4

commands.forEach(({name, command}) => {
  Cypress.Commands.addQuery(name, command)
})

What you did: Update cypress to latest version (13.4.0). Update @testing-library/cypress to latest version (10.0.1)

What happened: Cypress started in gui mode without issues. When running a test, it fails with the following error:

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.

Reproduction repository: Already described above under what you did

Problem description: Looks like testing-library is trying to recreate a function that already exists in cypress.

Suggested solution: Either use the built in method from cypress, or use Cypress.Commands.overrideQuery() instead in this case.

brycefranzen commented 9 months ago

After further reading error logs, it appears this may actually be an issue in the https://github.com/kentcdodds/dom-testing-library repo. I assumed it was here since the error was thrown within the scope of this repos code. However, it appears that the offending code that caused the error may be in the other repo after-all 🤷🏼‍♂️

If that's the case, feel free to close/recreate this issue over there.

Thanks!

Oputo50 commented 9 months ago

I'm facing the exact same issue. Any idea of how to workaround it?

rszalski commented 7 months ago

Ran into the same issue. Looks like there already is a GH issue for this with more details and potential solution: https://github.com/testing-library/cypress-testing-library/issues/251.

I suggest this is closed as a duplicate.