Skip to the page

Testing a UI feature and estimating · core

Test layers and flaky end-to-end tests

Most value is in integration tests that render a feature with the network mocked. Unit tests cover pure logic, and a few end-to-end journeys run in a real browser. Flaky tests are bugs to quarantine and fix.

The notes

What you must know

  • Unit: pure logic with many cases (price totals, coupon rules, reducers, formatters). Integration, where most tests go: a feature rendered with Testing Library, real child components and the network mocked by MSW, asserting what the user sees and can do.
  • End to end: a few critical journeys (search, cart, pay) in a real browser against a test environment. They are slow, costly and flakier but closest to reality.
  • Also: contract tests for API shapes, visual tests for the design system and static checks (TypeScript, ESLint) as the base layer. React Native: Jest with React Native Testing Library, plus Maestro or Detox for a few device flows.
  • Coverage is not quality: tests of implementation details, or tests that mock everything, give false confidence.
  • Plan for one week: end-to-end tests for checkout and login first, then integration tests for the cart.
  • Flaky tests: measure with CI history (pass only on retry means flaky) and run suspects 50 times (--repeat-each); record traces on first retry.
  • Causes: fixed waits (waitForTimeout), CSS or XPath locators that change, order or shared data, animations, real third-party calls, time zones and dates, limited CI resources.
  • Fixes: web-first assertions (expect(locator).toBeVisible()), role and test-id locators, page.route to mock third parties and the Playwright clock API for time. Quarantine with an owner and a ticket. Retries report flakiness but are never the fix.

The red pen

Common traps: mistake → fix

  • Mistake: More end-to-end tests are better

    Fix: they are slow and flaky; keep few.

  • Mistake: Retry in CI fixes flaky tests

    Fix: it hides them.

  • Mistake: Testing component internals shows quality

    Fix: test what the user sees and does.

Easy to hard

Questions interviewers ask, easy to hard

  1. What do you unit test, integration test and end-to-end test in a frontend?
  2. Our end-to-end tests are flaky. What do you do?
  3. You have one week to add tests to an untested app. Where do you start?
  4. Why do some tests fail only in CI?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview