-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retry mechanism of 'should' can erroneously cause the arguments to .should() to be null when cy.log() in fn #8346
Comments
Yeah, this is definitely incorrect behavior. Just to remove the concept of negating the assertions, the code below demonstrates the problem with just checking existence alone. This seems to have always been the behavior, went back to Cypress 3.4.1. Repro<html>
<body>
<div id="thisElIsFound">El</div>
</body>
</html> it('test', () => {
cy.visit('index.html')
cy.get('#thisElIsFound').should((el) => {
expect(el).to.exist // passes, element exists
})
cy.get('#thisElIsFound').should((el) => {
expect(el).to.exist // fails, expected null to exist
cy.log('As we thought, it is there')
})
}) The |
Another example of this bug found in #9435 The cy.log() runs twice. it('test', () => {
cy.get('div').should(($element) => {
cy.log($element)
})
}) |
The command is run twice because the The workaround is to use it('test', () => {
cy.visit('fixtures/a.html')
cy.get('#thisElIsFound').should((el) => {
expect(el).to.exist
Cypress.log({
displayName: 'log',
message: 'As we thought, it is there',
})
})
}) If you don't want to use it('test', () => {
cy.visit('fixtures/a.html')
cy.get('#thisElIsFound').then((el) => {
expect(el).to.exist
cy.log('As we thought, it is there')
})
}) |
Closing this as duplicate of #22587, which now has an associated PR. |
Current behaviour:
If I want to assert an element doesn't exist in the DOM, I have the option of simply doing something like:
However, in the logging, this simply returns a rather crude
Expected null not to exist
. In my view, a better way of doing the assertion is:Which produces a log of
Expected #notFound to not exist
- which is far more informative.However, I've discovered that if I then try and do more within the 'should' block, Cypress fails, reporting that it DID expect to find the element:
This produces 'Timed out retrying: Expected to find element: #notFound , but never found it.'
Similarly, the following works:
Yet the following returns 'expected null to exist'
Desired behavior:
All the following statements should pass - the only difference being, the last two should produce the
cy.log
statements. In summary, it should be possible to do more than just a simple expect statement within the should block.Test code to reproduce
Please see above - obviously you'll need to substitute the selectors as appropriate!
Versions
Cypress 12.1, CentOS 8, Chrome 83.
The text was updated successfully, but these errors were encountered: