0
0
Cypresstesting~20 mins

Component testing vs E2E in Cypress - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Component vs E2E Testing
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between Component Testing and E2E Testing

Which statement best describes the main difference between component testing and end-to-end (E2E) testing in Cypress?

AComponent testing focuses on testing individual UI components in isolation, while E2E testing verifies the entire application flow from start to finish.
BComponent testing runs tests only on backend APIs, while E2E testing runs tests only on frontend UI components.
CComponent testing requires a full database setup, while E2E testing uses mocked data only.
DComponent testing is slower than E2E testing because it tests the whole app, while E2E testing is faster because it tests small parts.
Attempts:
2 left
💡 Hint

Think about the scope each testing type covers.

Predict Output
intermediate
2:00remaining
Output of a Cypress Component Test

Given this Cypress component test code, what will be the test result?

Cypress
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');
  });
});
ATest fails because the button text is empty.
BTest passes because the button text matches 'Click me'.
CTest fails with a selector error because 'button' is not found.
DTest fails due to a syntax error in the component code.
Attempts:
2 left
💡 Hint

Check what the component renders and what the assertion checks.

assertion
advanced
2:00remaining
Correct Assertion for E2E Login Test

In an E2E test for a login page, which assertion correctly verifies that the user is redirected to the dashboard after login?

Cypress
cy.visit('/login');
cy.get('#username').type('user1');
cy.get('#password').type('pass123');
cy.get('button[type=submit]').click();
Acy.get('button[type=submit]').should('be.disabled');
Bcy.get('h1').should('contain.text', 'Login');
Ccy.url().should('include', '/dashboard');
Dcy.get('#username').should('be.visible');
Attempts:
2 left
💡 Hint

Think about what confirms successful navigation after login.

🔧 Debug
advanced
2:00remaining
Debugging a Failing Component Test

This Cypress component test fails with 'Timed out retrying: Expected to find element: button, but never found it.' What is the likely cause?

Cypress
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');
  });
});
AThe component renders an <a> tag, but the test looks for a <button> element.
BThe mount function is missing a required argument.
CThe test is missing a wait command before cy.get.
DThe component code has a syntax error causing it not to render.
Attempts:
2 left
💡 Hint

Check the element types in the component and the test selector.

framework
expert
2:30remaining
Choosing Test Types for a Complex Web App

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?

AWrite only component tests because E2E tests are too slow and flaky.
BWrite only E2E tests covering all user flows to avoid duplication.
CWrite unit tests for backend APIs and skip frontend testing.
DWrite extensive component tests for UI parts and a few critical E2E tests for main user flows.
Attempts:
2 left
💡 Hint

Consider speed, coverage, and reliability of tests.