cy.get('.item-list > li').should('have.length', 5);
Option A uses the correct Cypress assertion have.length to check the exact number of elements. Option A checks for greater than 5, which is not exact. Option A uses an invalid assertion name. Option A uses a non-existent assertion.
cy.get('.todo-item').should('have.length', 5);
Cypress throws an AssertionError when the actual number of elements does not match the expected length. It reports the actual and expected values.
data-test='list-item'. Which locator is best for stable length assertions?Option A uses a stable data attribute selector which is less likely to break if classes change. Other options rely on classes or tags that may be unstable or too broad.
cy.get('.menu-item').should('have.length', 3);The error says actual length is 2. What is the most likely cause?
The error indicates the selector found 2 elements, but the test expects 3. This usually means the page content does not have the expected number of elements at test time.
cy.get('.container').find('.card').should('have.length', 4);What does this assertion verify?
The find() command searches within all matched '.container' elements and returns all '.card' elements found. The assertion checks the total count of these '.card' elements combined.