Part IV — Frontend Testing
Nobody is hired for knowing the Vitest API. What gets tested in an interview is judgement: what is worth testing, at which layer, and what a test is allowed to know about the implementation. This section is organised around that question. The framework material is thin on purpose. It is only the vocabulary you need to have the real conversation.
The through-line is coupling. A test that knows about internal state breaks on every refactor. It teaches the team to distrust the suite. A test that drives the interface the way a user does survives rewrites of everything underneath it. Almost every recommendation here follows from that one idea.
Chapters
| # | Chapter | What it answers |
|---|---|---|
| 01 | Testing Strategy | What do you test, at which layer, and what does it cost? |
| 02 | Writing the Tests: Vitest and React Testing Library | Which query, and where do you mock, so a refactor does not break a hundred tests? |
| 03 | Frontend Integration Testing | How do you test a whole flow against a faked network? |
| 04 | End-to-End, Visual and Contract Testing with Playwright | Which browser tests earn their runtime, and what about failures an assertion cannot express? |
| 05 | Testing Accessibility | What can be gated in CI, and what has to be done by hand? |
Chapter 05 is the book's one home for testing accessibility. It owns the method, the CI gate and the two manual passes, so other chapters point at it rather than restate it.
What Interviewers Probe For
A test suite spends three budgets: runtime, maintenance and trust.
- Where do you draw the test boundary? The strongest answer names the network as the mock point and tests everything above it together. Mocking a child component is usually a sign the boundary is in the wrong place.
- How do you handle a flaky test? Quarantine and fix, not retry and forget. A candidate who reaches straight for a retry count has told you what their suite looks like.
- Where does component testing stop and end-to-end start? The answer is about what is real, not about how long the flow is. jsdom (the fake DOM most unit tests run in) computes no layout.
- What is your coverage number for? The honest senior answer: coverage finds untested files, not untested behaviour. A target above roughly 80% starts buying tests written to satisfy the number.
- When do you not write the test first? TDD is a tool, not a creed. Exploratory work, spike code and UI layout are the honest exceptions. Saying so reads as experience, not laziness.
Reading Order
Read 01 first. It sets the layers everything else refers to. Then read 02 and 03, where most frontend testing actually happens. 04 and 05 are the judgement chapters and read well in one sitting.
Interview sprint: 01 → 02 → 04. The layering question, the query-priority question, and knowing which end-to-end tests earn their place cover most of what gets asked.