should('have.length.above') suppresses other assertion messages
See original GitHub issueIf I chain assertions after .should('have.length.above')
then some of the assertions after it are not shown on the log.
Example:
describe('Cypress', () => {
it('can display all assertions after "have.length.above"', () => {
cy.visit('https://developer.mozilla.org/en-US/');
cy.get('.hero-content')
.should('have.length.above', 0)
.should('contain', 'Resources') // this command runs, but it is never logged unless it fails
.should('contain', 'developers'); // this command is logged even when passing (expected behavior)
})
// example without browsing to a page
it('can display all assertions after "have.length.above" without a webpage', () => {
const array = [1, 2, 3];
cy.wrap(array)
.should('have.length.above', 1)
.should('contain', 1)
.and('contain', 2);
})
})
Notice how there is only 1 message for the 2 'contain'
assertions, it only shows the second one.
If we change the test and convert 'have.length.above', 0
to 'have.length', 1
, then both assertions are shown:
In this image we can see both Resources
and developers
in the assertions.
Versions
Tested on Cypress v6.9.1 and v7.4.0, with Chrome and Electron.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Assertion have.length.above is not working as expected #18678
Current behavior I have a bunch of elements with data-test="comment-bubble". Getting them is working as intended, but checking their length ...
Read more >Text assertion in Cypress with nested query - Stack Overflow
Text length should be greater than 1, and less than 20. My code is as follows. getUserFirstName(textInput) { cy.get('[testid= ...
Read more >Assertions | Cypress Documentation
Cypress bundles the popular Chai assertion library, as well as helpful extensions for Sinon and jQuery, bringing you dozens of powerful assertions for....
Read more >Java static code analysis: Assertion methods should not be ...
AssertJ assertions with "Consumer" arguments should contain assertion inside consumers ... Collection sizes and array length comparisons should make sense.
Read more >Assertion Styles - Chai
lengthOf(foo, 3, 'foo`s value has a length of 3'); assert. ... These will be included in the error messages should your assertion not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like maybe another example of this issue https://github.com/cypress-io/cypress/pull/16218, where some
.contains()
assertions followed by certain assertions don’t show all.contains()
logs. cc @sainthkhReproducible example
@sainthkh Yeah, I thought this was what this code was for. I remember when it used to log every single retry attempt in the runner, sometimes hundreds of them. 😆 Let’s not do this, but maybe there’s a way to be smarter about the merge via the message content rather than a count.