What to test
5 minTests earn their keep when they check what a person can do, and break only when that changes. You'll sort ten real checks into worth it or skip.
Lesson video
Tastebud · 5:19 · Captions on screen
Test the behaviour people rely on, and leave out the details a redesign will change.
- Why. A test earns its upkeep when it fails only if someone's task breaks. Tests tied to class names or exact colours fail on harmless changes, and people stop trusting them.
- Real example. Tap Subscribe and the channel's new videos land in Subscriptions, up to 75 new channels a day. That outcome is worth a test; the button's exact colour isn't. (YouTube, Nov 2026)
- When to break it. Pin a detail when the detail is the behaviour. A legal disclaimer's exact wording, or a price format like ₹1,499, deserves an exact test.
- Common mistake. Snapshotting a whole page's HTML. Every redesign turns it red, people press update without reading the diff, and a real bug ships inside it.
Our take. Test what a person can do with a tap, a key or a screen reader, never your class names or a snapshot of the whole page. Those break on every redesign and teach a team to press update without reading.
Decide what to test by what the person does
What a person does on the screen decides the tests: reading the count, pressing Subscribe, finding it with a keyboard or a screen reader. Each of those is worth a test. Colours, timings and class names will change.
Recreated from YouTube's channel page, Nov 2026. Tap each part for what's worth testing.
Tests that break on redesigns, beside tests that last
A test that finds Subscribe by its role and name keeps passing when a designer renames classes or swaps the colour. One that finds '.sub-btn--dark' fails on the next redesign, though nothing broke for anyone.
- Finds the button by .sub-btn--dark
- Expects the background to be #0f0f0f
- Checks the isSubscribed state
- Snapshots the whole page's HTML
- Finds the button by its role and name
- Checks the text passes 4.5:1 contrast
- Checks it now says Subscribed
- Presses it with Tab and Enter
A test that broke on a redesign, rewritten to last
A redesign renamed the button's classes and the test went red, though Subscribe still works. A test that finds the button by its name, presses it and checks the words a person reads keeps passing.
The rewritten test does what a person does, so a class rename can't break it
- Find the button named Subscribe. By its words, the way a person or a screen reader finds it. The old test looked for .sub-btn--dark, a class the redesign renamed.
- Press it. A click, the same as a tap. In Playwright you'd find it with getByRole and its name.
- Read the words it shows. The test checks what a person reads, never a class or a state variable.
- Expect Subscribed. If the button now says Subscribed, subscribing works.
- Passes through redesigns. Classes and colours can change again. The test fails only when subscribing really breaks.
Try it
Worth a test, or skip it?
Someone proposed ten checks for a Subscribe button like YouTube's. Decide each one, then read why.
Make the test check what people see
Edit the test in the JavaScript, below the component. Find the button whose text is 'Subscribe', click it, and check its text is now 'Subscribed'. Leave class names out. One way to find it: [...document.querySelectorAll('button')].find((b) => b.textContent === 'Subscribe').
Tab adds two spaces. Press Esc, then Tab, to leave the editor.
- The test finds the button by its name, Subscribe (not yet)
- It checks the words a person reads after pressing (not yet)
- No class names in the test (not yet)
What to notice: Watch the result under the channel. It says FAIL on the starter, though Subscribe works when you press it. Once the test finds the button by its name and checks the new words, it says PASS.
Quick check
A designer changes the Send button from blue to green across the library, and twelve tests fail. What does that tell you?
Watch next
Watch it for Why tests of pieces working together give the most confidence for the time they take.
Watch it for Finding elements by role and name, the way a person or a screen reader would, instead of by CSS class.
Connects to: 8.2 Keyboard and focus · 8.5 Accessibility testing · 13.4 Tests and linting · 20.4 Reviewing your own work
Sources · checked Nov 2026
- YouTube Help: Subscribe to YouTube channelsA Subscribe button sits under every video and on a channel page; new videos from subscribed channels show in Subscriptions; the limit is 75 new channels a day, with a Too many subscriptions error
- YouTube channel page: Chrome for Developers (read 26 Nov 2026)UI wording: the channel name, @ChromeDevs, 823K subscribers and a Subscribe button
- MDN: button elementA native button is focusable and works with Enter and Space, and screen readers announce its role and name
- Playwright: Best practicesTest user-visible behaviour and avoid implementation details such as function names or the CSS class of an element; locate elements with getByRole
- Testing Library: Guiding principlesThe more your tests resemble the way your software is used, the more confidence they can give you
- Testing Library: About queries (priority)Queries accessible to everyone come first, with getByRole and an accessible name at the top
- Martin Fowler: Test Pyramid (1 May 2012)Many more low level tests than broad tests through the user interface; mostly UI tests is the ice-cream cone, slow and hard to run
- Playwright release notes1.65 is the newest release listed; npm shows 1.65.1 as latest, published 13 Nov 2026
- Playwright home pageOne API to drive Chromium, Firefox and WebKit
- Playwright API: Page (getByRole, locator)getByRole matches the name as a case-insensitive substring by default; exact: true matches it case-sensitively and as the whole string; page.locator takes a selector
- Vitest 5 announcementVitest 5.1.2 (25 Nov 2026); Browser Mode stable; toMatchScreenshot for visual tests
- axe-core on GitHubaxe-core 4.14.1 checks WCAG 2.0, 2.1 and 2.2 rules, including colour contrast
- WCAG 2.2: 1.4.3 Contrast (Minimum)Body text needs a contrast ratio of at least 4.5:1