0
0
Cypresstesting~10 mins

Length assertions in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check that the list has exactly 5 items.

Cypress
cy.get('ul#items > li').should('have.length', [1]);
Drag options to blanks, or click blank then click option'
A5
B3
C0
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong number in the assertion causes the test to fail.
Forgetting to use 'have.length' and using 'length' instead.
2fill in blank
medium

Complete the code to assert that the input field has no characters (length 0).

Cypress
cy.get('input#username').invoke('val').should('have.length', [1]);
Drag options to blanks, or click blank then click option'
A1
Bnull
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes the test to fail because the input is empty.
Not using invoke('val') to get the input value.
3fill in blank
hard

Fix the error in the assertion to check the number of buttons is 4.

Cypress
cy.get('button').should('have.[1]', 4);
Drag options to blanks, or click blank then click option'
Alength
Blengths
ClengthOf
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'have.lengths' or 'have.count' causes syntax errors.
Misspelling 'length' breaks the test.
4fill in blank
hard

Fill both blanks to check that the paragraph text length is greater than 10 characters.

Cypress
cy.get('p.description').invoke('text').should('have.length[1]', [2]);
Drag options to blanks, or click blank then click option'
A.gt
B.eq
C10
D.lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.eq' instead of '.gt' causes the test to check for exact length 10, not greater.
Using '.lt' checks for less than 10, which is incorrect here.
5fill in blank
hard

Fill both blanks to assert that the list items count is at least 3.

Cypress
cy.get('ul#tasks > li').should('have.length[1]', [2]);
Drag options to blanks, or click blank then click option'
A.eq
B.gte
C3
D.lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.eq' checks for exactly 3, not at least 3.
Using '.lt' checks for less than 3, which is wrong here.