You rename one CSS class. You click around the app and everything works. Then you run your tests, and half of them are red.
Nothing is broken for your users. Your tests were just looking at the wrong things.
That's the problem Testing Library solves. Testing Library is a set of small tools that test your UI the way a person uses it: find things by what they see, do what they do, and check what shows up on the screen. React Testing Library is the version for React.
Let's learn it with one tiny component and one button.
Meet the button
Here's the whole component we'll test. A heading, an email box and a Subscribe button. When you submit, a thank-you line appears.
// Subscribe.jsx import { useState } from 'react' ;
export function Subscribe ( ) { const [ done , setDone ] = useState ( false ) ;
return ( < form onSubmit = { ( e ) => { e .β¦