"Tests exist so you can change code without holding your breath."
The Religious Answer (Skip It)
The religious answer to "why test?" usually goes: "tests prove correctness," "TDD is the only true way," "100% coverage means quality." Every one of those is wrong, and the working engineers shipping production code know it. Tests don't prove correctness — they sample it. TDD is one workflow among several. Coverage is a lagging indicator that 100% of garbage is still garbage.
The Working-Engineer Answer
The real reason to test is this: so you can change code without holding your breath. Six months from now, you'll need to refactor that auth handler, or upgrade Next.js by two majors, or replace a library that just got abandoned. The test suite is the only thing standing between you and "did I just break something I forgot about?"
Everything else — coverage percentage, code-review check marks, even catching bugs at the moment they appear — is a side effect. The primary value is trust. A passing suite buys you the right to change things.
The Shape Every Test Takes — AAA
Arrange. Act. Assert.
Arrange the world — set up inputs, fixtures, mocks. Act on the code under test — call the function, click the button. Assert the result — check what came back, what changed, what got called.
Some tests are tiny enough that the three steps blur into one line. But the shape is still there. If a test feels chaotic, it's usually because AAA got mangled — too much arranging happens inside the act, or assertions get sprayed through the body. Pull them apart and the test reads itself.
What Tests Are NOT
Tests are not proof of correctness — you can't enumerate every input. Tests are not specification — specs change, tests are commits. Tests are not documentation — mostly, though a good test name reads like one. Tests are not code review, and a green suite doesn't mean a good design.
They are: a safety net that catches the small drops, and a tripwire for the big ones. That's all. That's enough.