Which statement best describes the main difference between component testing and end-to-end (E2E) testing in Cypress?
Think about the scope each testing type covers.
Component testing isolates and tests individual UI parts, while E2E tests simulate real user scenarios across the full app.
Given this Cypress component test code, what will be the test result?
import { mount } from 'cypress/react'; function Button({label}) { return <button>{label}</button>; } describe('Button component', () => { it('renders correct label', () => { mount(<Button label="Click me" />); cy.get('button').should('have.text', 'Click me'); }); });
Check what the component renders and what the assertion checks.
The Button component renders a button with the label 'Click me'. The test checks that the button's text matches exactly, so it passes.
In an E2E test for a login page, which assertion correctly verifies that the user is redirected to the dashboard after login?
cy.visit('/login'); cy.get('#username').type('user1'); cy.get('#password').type('pass123'); cy.get('button[type=submit]').click();
Think about what confirms successful navigation after login.
Checking the URL includes '/dashboard' confirms the user was redirected after login. Other options check unrelated elements.
This Cypress component test fails with 'Timed out retrying: Expected to find element: button, but never found it.' What is the likely cause?
import { mount } from 'cypress/react'; function Link() { return <a href="#">Click here</a>; } describe('Link component', () => { it('renders a button', () => { mount(<Link />); cy.get('button').should('exist'); }); });
Check the element types in the component and the test selector.
The component renders an anchor tag, but the test searches for a button, so the element is never found.
You are testing a complex web app with many UI components and user flows. Which Cypress testing strategy combination is best to ensure fast feedback and full coverage?
Consider speed, coverage, and reliability of tests.
Component tests give fast feedback on UI parts, while E2E tests ensure critical flows work end-to-end. Combining both balances speed and coverage.