Bird
0
0

Why is it important to call cy.injectAxe() after cy.visit() and before cy.checkA11y() in Cypress tests?

hard📝 Conceptual Q10 of 15
Cypress - Plugins and Ecosystem
Why is it important to call cy.injectAxe() after cy.visit() and before cy.checkA11y() in Cypress tests?
ABecause <code>cy.checkA11y()</code> automatically injects axe if missing.
BBecause axe-core must be loaded into the page DOM before accessibility checks can run.
CBecause <code>cy.injectAxe()</code> resets the page state and must come last.
DBecause <code>cy.visit()</code> disables accessibility testing until injection.
Step-by-Step Solution
Solution:
  1. Step 1: Understand axe-core injection timing

    Axe-core library must be loaded into the page's DOM to perform accessibility audits.
  2. Step 2: Confirm command order necessity

    Visiting the page loads the DOM, then injecting axe adds the library, enabling checkA11y to run properly.
  3. Final Answer:

    Because axe-core must be loaded into the page DOM before accessibility checks can run. -> Option B
  4. Quick Check:

    Inject axe after visit to enable accessibility checks [OK]
Quick Trick: Inject axe after page load, before checking accessibility [OK]
Common Mistakes:
  • Thinking injectAxe resets page state
  • Assuming checkA11y auto-injects axe
  • Believing visit disables accessibility testing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes