Bird
0
0

Identify the issue in this Cypress component test setup:

medium📝 Debug Q6 of 15
Cypress - Component Testing
Identify the issue in this Cypress component test setup:
import { mount } from 'cypress/react';
import Widget from './Widget';
describe('Widget tests', () => {
  beforeEach(() => {
    mount();
  });
  it('should render widget container', () => {
    cy.get('.widget-container').should('exist');
  });
});
AThe mount function is called outside the test block
BMissing import of React in the test file
CbeforeEach should not be used with mount()
DThe selector '.widget-container' might be incorrect or missing in the component
Step-by-Step Solution
Solution:
  1. Step 1: Review the test code

    The test mounts the Widget component before each test and checks for an element with class .widget-container.
  2. Step 2: Identify potential issues

    If the component does not render an element with class widget-container, the test will fail.
  3. Step 3: Other options

    React import is not mandatory in newer JSX setups, beforeEach is valid for mounting, and mount() is correctly called inside beforeEach.
  4. Final Answer:

    The selector '.widget-container' might be incorrect or missing in the component -> Option D
  5. Quick Check:

    Check if selector matches component output [OK]
Quick Trick: Verify selectors match component DOM [OK]
Common Mistakes:
  • Assuming React import is always required
  • Thinking mount() can't be used in beforeEach
  • Confusing mount placement inside test blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes