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: cy.get('#submit').should('not.be.disabled') 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')
✗ 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?
AThe login element is disabled
BThe login element is visible
CThe login element is enabled
DThe login element does not exist
✗ Incorrect
The assertion checks that the element with id 'login' is NOT disabled, meaning it is enabled.
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
✗ 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'?
What will happen if the element .alert is present but hidden?
medium
A. The first assertion fails, the second passes.
B. The first assertion passes, the second fails.
C. Both assertions pass.
D. Both assertions fail.
Solution
Step 1: Analyze should('not.exist') when element is present but hidden
This assertion fails because the element exists in the DOM, even if hidden.
Step 2: Analyze should('not.be.visible') when element is hidden
This assertion passes because the element is present but not visible.
Final Answer:
The first assertion fails, the second passes. -> Option A
Quick Check:
Existence vs visibility differ: exist fails, visibility passes [OK]
Hint: Existence and visibility are different checks [OK]
Common Mistakes:
Assuming 'not.exist' passes if element is hidden
Confusing visibility with existence
Thinking both assertions behave the same
4. You wrote this Cypress test:
cy.get('.popup').should('not.exist')
But the test fails even though the popup is hidden. What is the likely problem?
medium
A. The selector '.popup' is incorrect.
B. The popup element exists but is hidden, so 'not.exist' fails.
C. The test should use 'should('not.be.visible')' instead.
D. Cypress cannot check hidden elements.
Solution
Step 1: Understand difference between 'not.exist' and hidden elements
'not.exist' fails if element is present in DOM, even if hidden.
Step 2: Apply to the popup element
The popup is hidden but still in DOM, so assertion fails because element exists.
Final Answer:
The popup element exists but is hidden, so 'not.exist' fails. -> Option B
Quick Check:
'not.exist' means element absent, hidden still exists [OK]
Hint: Hidden elements still exist; use 'not.be.visible' for hidden check [OK]
Common Mistakes:
Using 'not.exist' to check hidden elements
Assuming hidden means not in DOM
Ignoring difference between visibility and existence
5. You want to verify that a div with class .notification is neither present nor visible on the page. Which Cypress code correctly checks both conditions?
hard
A. cy.get('.notification').should('not.exist').and('not.be.visible')
B. cy.get('.notification').should('not.exist'); cy.get('.notification').should('not.be.visible')
C. cy.get('.notification').should('not.be.visible')
D. cy.get('.notification').should('not.exist')
Solution
Step 1: Understand that if element does not exist, it cannot be visible
If the element does not exist in the DOM, it is automatically not visible.
Step 2: Check which assertion covers both absence and visibility
Using should('not.exist') alone is enough to confirm element is absent and thus not visible.
Final Answer:
cy.get('.notification').should('not.exist') -> Option D
Quick Check:
Not existing means not visible too [OK]
Hint: Check 'not.exist' alone to confirm absence and invisibility [OK]
Common Mistakes:
Chaining 'not.exist' with 'not.be.visible' unnecessarily
Running two separate assertions causing flaky tests
Using only 'not.be.visible' when element might exist
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.