cy.contains('xxx').should('not.exist') try to expect <body> not to exist in the DOM
See original GitHub issueCurrent 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

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:
- Created 3 years ago
- Comments:8 (3 by maintainers)
I ran into this on my Next app, found that
cy.contains
matches thebody
when used in combination with Next’sgetStaticProps
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 whichcy.contains
matches/works against.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.