Testing
Unit, integration and end-to-end tests that catch real bugs.
14 lessons 25 practice questions about 1 hours of reading
Chapter 1, beginner
Foundations
What it is and how it works, the questions every round starts with.
- 01getBy vs queryBy vs findBy in React Testing Library: which one to use?
Lesson, 4 min read, then 4 questions to practise
- Implement Testing Library's getByText and getByLabelText: text normalisation, matchers and helpful errors
- Test what users see: pick queries, spot implementation-detail tests and implement getByRole
- Replace fixed sleeps in flaky tests with waitFor(assertion, { timeout, interval })
- Build renderHook() to test custom hooks: result.current, rerender with new props, unmount, act and wrappers
- 02Unit vs integration vs end-to-end tests
Lesson, 5 min read, then 4 questions to practise
- Write unit tests for a debounce hook and a search component that catch real bugs
- Make visual and accessibility regression tests stable: fix noisy screenshots and pick the right test layer
- Bug squash: make six failing tests of an unfamiliar cart module pass without touching the tests
- Build a mini test runner with describe, it, hooks and timeouts
- 04What is test-driven development (TDD)?
Lesson, 4 min read, then 2 questions to practise
Chapter 2, intermediate
In depth
How it behaves under the hood, and the follow-ups that come next.
- 05fireEvent vs userEvent: what is the difference?
Lesson, 4 min read, then 2 questions to practise
- 06How do you test asynchronous code and timers in Jest?
Lesson, 5 min read, then 2 questions to practise
- 07How do you test custom React hooks?
Lesson, 4 min read, then 1 question to practise
- 08How do you write reliable end-to-end tests with Playwright?
Lesson, 5 min read, then 1 question to practise
- 09Jest vs Vitest: speed, mocking and how to migrate
Lesson, 4 min read
- 10jest.fn vs jest.spyOn vs jest.mock: what is the difference?
Lesson, 5 min read, then 5 questions to practise
- Implement jest.fn() mock functions: mockReturnValueOnce, mockResolvedValue, mock.results and mockReset
- Implement jest.spyOn() with call records, mockImplementation and restore
- Build a jest.mock-style module registry: factories, automocks, requireActual, resetModules and isolateModules
- Build asymmetric matchers: expect.any, objectContaining, arrayContaining, stringMatching and toHaveBeenCalledWith
- Build an MSW-style request mocker: path params, server.use overrides, once handlers and unhandled requests
- 11Playwright vs Cypress: what is the difference?
Lesson, 4 min read
- 12What is React Testing Library, and how should you test components?
Lesson, 4 min read
- 13What is snapshot testing, and when should you use it?
Lesson, 4 min read, then 1 question to practise
- 14What should you test in a frontend app? The testing trophy explained
Lesson, 5 min read, then 1 question to practise