unit test
A unit test is a tiny piece of code whose only job is to check that one small piece of your real code does what it's supposed to. You feed it a known input, say what answer you expect, and the test shouts if reality disagrees. The 'unit' is the smallest sensible thing to test on its own — usually a single function.
Each one is dead simple: 'when I add 2 and 3, I expect 5'. On its own that feels almost too obvious to bother writing. The payoff comes from having hundreds of them and running the whole batch in seconds. Change one line of code, run the tests, and they instantly tell you whether you just quietly broke something three files away.
That's the real gift — a safety net. Without tests, every change is a small gamble: did this break anything? With them, you edit boldly, run the suite, and trust the green checkmarks. They're also living documentation: reading a test shows exactly how a piece of code is meant to be used.
function add(a, b) { return a + b; }
test("adds two numbers", () => {
expect(add(2, 3)).toBe(5); // pass if add really returns 5
});Known input, expected answer — the test fails loudly the day 'add' stops returning 5.
Wired into a CI/CD pipeline, the whole suite runs automatically on every push — so a broken change gets caught before anyone else ever sees it.