A. Because cy.clearCookies is missing parentheses to call the function
B. Because afterEach only runs before tests
C. Because cy.clearCookies is not a valid Cypress command
D. Because beforeEach overrides afterEach
Solution
Step 1: Check the afterEach hook code
The code uses cy.clearCookies without parentheses, so the function is not called.
Step 2: Understand function call syntax
To execute the command, parentheses are required: cy.clearCookies().
Final Answer:
Because cy.clearCookies is missing parentheses to call the function -> Option A
Quick Check:
Functions need () to run [OK]
Hint: Always add () to call Cypress commands [OK]
Common Mistakes:
Forgetting parentheses on Cypress commands
Confusing beforeEach and afterEach roles
Assuming afterEach runs before tests
5. You want to test a form that requires logging in before each test and clearing local storage after each test. Which is the best way to organize your Cypress hooks?
hard
A. Use only beforeEach for both login and clearing local storage
B. Use afterEach to log in and beforeEach to clear local storage
C. Use only afterEach for both login and clearing local storage
D. Use beforeEach to log in and afterEach to clear local storage
Solution
Step 1: Identify setup and cleanup tasks
Logging in is setup needed before each test; clearing local storage is cleanup after each test.
Step 2: Assign tasks to correct hooks
Use beforeEach for setup (login) and afterEach for cleanup (clear local storage).
Final Answer:
Use beforeEach to log in and afterEach to clear local storage -> Option D
Quick Check:
Setup beforeEach, cleanup afterEach [OK]
Hint: Setup in beforeEach, cleanup in afterEach [OK]
Common Mistakes:
Mixing setup and cleanup in wrong hooks
Using only one hook for both tasks
Not cleaning up after tests
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.