Bird
0
0

You have this Cypress test:

medium📝 Debug Q6 of 15
Cypress - Plugins and Ecosystem
You have this Cypress test:
cy.visit('/profile')
cy.checkA11y()

It throws an error stating axe is not defined. What is the most probable reason?
AThe <code>cy.visit()</code> command was called with an invalid URL.
BYou forgot to call <code>cy.injectAxe()</code> before <code>cy.checkA11y()</code>.
CThe <code>cy.checkA11y()</code> command requires a selector argument.
DThe axe-core library is not installed in the project dependencies.
Step-by-Step Solution
Solution:
  1. Step 1: Understand error cause

    The error indicates axe-core is not available in the page context.
  2. Step 2: Missing injection

    Without calling cy.injectAxe(), axe-core is not loaded, causing the error.
  3. Step 3: Other options

    Invalid URL or missing selector do not cause axe not defined errors; missing dependency would cause build errors, not runtime.
  4. Final Answer:

    You forgot to call cy.injectAxe() before cy.checkA11y(). -> Option B
  5. Quick Check:

    Always inject axe before checking [OK]
Quick Trick: Inject axe before checking accessibility to avoid errors [OK]
Common Mistakes:
  • Assuming checkA11y needs a selector
  • Blaming cy.visit for axe errors
  • Thinking axe-core must be manually imported in test

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes