Execution Trace Quiz - 3 Questions
Test your understanding
What does the beforeEach hook do in this test suite?
beforeEach runs before every test, ideal for resetting state.before runs once before all tests, after and afterEach run after tests, so they don't reset state before tests.describe('My Tests', () => {
beforeEach(() => {
cy.visit('/login')
})
it('Test A', () => {
cy.get('#username').type('user1')
cy.get('#password').type('pass1')
cy.get('button').click()
cy.url().should('include', '/dashboard')
})
it('Test B', () => {
cy.get('#username').type('user2')
cy.get('#password').type('pass2')
cy.get('button').click()
cy.url().should('include', '/dashboard')
})
})beforeEach here?beforeEach runs before every test, so it visits the login page before Test A and Test B.beforeEach to reset state, but tests still fail due to shared data. What is the likely mistake?before is used, it runs once before all tests, so state is not reset before each test.beforeEach to reset state and avoid shared data ensures each test is independent and reliable.Pass the test and this pattern moves unknown