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.

should('have.length.above') suppresses other assertion messages

See original GitHub issue

If 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);
    })
})

image

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:

image

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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Jun 2, 2021

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 @sainthkh

Reproducible example

it('can display all assertions after "have.length.above"', () => {
  cy.visit('index.html');
  cy.get('div')
    .should('have.length.above', 0)
    .should('contain', 'Testing') // this command runs, but it is never logged unless it fails
    .should('contain', 'Cypress') // this command is logged even when passing (expected behavior)
})
<html>
<body>
  <div>
    <h1>Testing with Cypress.</h1>
  </div>
</body>
</html>
Screen Shot 2021-06-02 at 2 55 29 PM
0reactions
jennifer-shehanecommented, Jun 14, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

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