Part 14 / Topic 6 of 7
What NOT to test: implementation details
A test that queries something only the implementation would ever look at breaks on a harmless refactor, for no real reason - and the fastest way to actually believe that, rather than just hear it stated, is to do the refactor and watch. examples/06_what_not_to_test_implementation_details.jsx has two versions of the same password-strength meter, with the identical user-facing contract ("Weak"/"Medium"/"Strong" shown as text) and completely different internals:
// V1: a plain CSS class
<div className={`meter-bar strength-${strength.toLowerCase()}`} />
// V2, a refactor six months later: an ARIA progressbar, no class names at all
<div role="progressbar" aria-valuenow={value} ...>{strength}</div>
A test written against getByText("Weak") passes, unchanged, against both versions - it never looked at how the word got onto the screen. A test written against container.querySelector(".strength-weak") finds the div in V1, and finds nothing at all in V2 - the exact same user-visible result, but the query that depended on an internal class name has nothing left to find (examples/06_what_not_to_test_implementation_details.test.jsx). That querySelector-based test is what this section is warning against; it is shown here finding null rather than as a test this course would actually ship, because a committed test suite should never contain a test written to demonstrate failing.
Done here? The practice set for Part 14 — including the solutions — is on the part page.