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?
✗ Incorrect
The correct commands to check an element is not visible are
.should('not.be.visible') and .should('be.hidden').What does
cy.get('#login').should('not.be.disabled') verify?✗ Incorrect
The assertion checks that the element with id 'login' is NOT disabled, meaning it is enabled.
Why are negative assertions important in tests?
✗ Incorrect
Negative assertions confirm that unwanted states or elements are absent, ensuring correct app behavior.
Which is the correct way to assert a button does NOT contain the text 'Cancel'?
✗ Incorrect
Use
.should('not.contain', 'Cancel') to assert the button does NOT contain the text 'Cancel'.What happens if a negative assertion fails during test execution?
✗ Incorrect
If a negative assertion fails, it means the unwanted condition was found, so the test fails.
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.