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.

cy.contains('xxx').should('not.exist') try to expect <body> not to exist in the DOM

See original GitHub issue

Current behavior

I try to test input validation by cypress When user enter page first time, user should not see the error message So I write test like this cy.contains('forgot_password_error_email_empty').should('not.exist'); but it seems that command try to expect body not to exist in the DOM so it fails in the end

2

When I reproduced my problem, I found this bug is related to next-i18n and only occur in next production build If I have translation key test (public/static/locales/en) cy.contains('test').should('not.exist') will check body exist or not

If I write cy.contains with selector cy.contains('span', 'test').should('not.exist'), the test will pass. But I think this is not the good solution.

Desired behavior

cy.contains should not check the body

Test code to reproduce

clone this project (https://github.com/aNyMoRe0505/next-cypress) npm install => npm run build => npm run start then npm run cypress:open to execute test

if you run in dev mode (npm run dev) everything works fine.

Versions

“cypress”: “^6.3.0”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
egucciarcommented, Mar 9, 2021

I ran into this on my Next app, found that cy.contains matches the body when used in combination with Next’s getStaticProps which prints out static prop data in a <script> tag to the dom for Rehydration.

To fix, as a work around, i can no longer rely on cy.contains to retrieve elements based on text.

suggestion solution would be to exclude script tags from which cy.contains matches/works against.

0reactions
cypress-bot[bot]commented, Nov 10, 2021

Released in 9.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v9.0.0, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cypress-io/cypress - Gitter
I want to use cy.get to query the new DOM after the re-render. But the DOM is updated but cypress seems to cached...
Read more >
cypress element is detached from the dom - You.com - You.com
Cypress requires elements be attached in the DOM to interact with them. The previous command that ran was: cy.get () This DOM element...
Read more >
Cypress HTML log is terrible at indicating cy.get() DOM ...
I think the log is pretty clear, it says the element <button.bp3-button> was supposed to not exist, but cypress found it. Also with...
Read more >
Changelog - Cypress Documentation
Now it's possible to explicitly assert the cookie did not exist with cy. ... Cypress will throw an error when a user attempts...
Read more >
Solving The Element Is Detached From DOM Error In Cypress
The "element is detached from DOM" is a sign of a problem, not the problem itself! There is a variety of ways the...
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