0
0
Cypresstesting~5 mins

Negative assertions (not) in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a negative assertion in Cypress?
A negative assertion checks that something does NOT happen or exist, like an element not being visible or not containing certain text.
Click to reveal answer
beginner
How do you write a negative assertion to check an element is not visible in Cypress?
Use .should('not.be.visible') on the element to assert it is hidden or not visible on the page.
Click to reveal answer
intermediate
Example: <br> cy.get('#submit').should('not.be.disabled') <br> What does this check?
It checks that the element with id 'submit' is not disabled, meaning it should be enabled and clickable.
Click to reveal answer
beginner
Why use negative assertions in testing?
Negative assertions help confirm that unwanted states or elements are absent, ensuring the app behaves correctly by not showing errors or disabled buttons when it shouldn't.
Click to reveal answer
intermediate
Write a Cypress negative assertion to check that a button does NOT contain the text 'Submit'.
Use cy.get('button').should('not.contain', 'Submit') to assert the button does not have the text 'Submit'.
Click to reveal answer
Which Cypress command checks that an element is NOT visible?
A.should('not.be.visible')
B.should('be.hidden')
C.should('not.exist')
D.should('be.visible')
What does cy.get('#login').should('not.be.disabled') verify?
AThe login element is disabled
BThe login element is visible
CThe login element is enabled
DThe login element does not exist
Why are negative assertions important in tests?
ATo confirm elements are present
BTo check unwanted states are absent
CTo speed up tests
DTo ignore errors
Which is the correct way to assert a button does NOT contain the text 'Cancel'?
Acy.get('button').should('have.text', 'Cancel')
Bcy.get('button').should('contain', 'Cancel')
Ccy.get('button').should('not.have.text', 'Cancel')
Dcy.get('button').should('not.contain', 'Cancel')
What happens if a negative assertion fails during test execution?
ATest fails
BTest passes
CTest is skipped
DTest retries automatically
Explain how to use negative assertions in Cypress with examples.
Think about how to confirm something is NOT present or NOT true.
You got /4 concepts.
    Describe a real-life scenario where negative assertions help improve test quality.
    Imagine testing a form where a submit button should only be enabled after filling fields.
    You got /3 concepts.