Unit Test
ELI5 — The Vibe Check
A unit test is like checking that one single LEGO brick isn't broken before you use it in your big castle. You test each tiny piece of code all by itself, so if something breaks, you know exactly which brick is the problem.
Real Talk
A unit test verifies the behavior of a single, isolated unit of code — typically a function or method. External dependencies are replaced with mocks or stubs so the test only exercises the logic of the unit under test.
Show Me The Code
function add(a, b) { return a + b; }
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
When You'll Hear This
"Write unit tests for that utility function." / "The unit tests pass but the app still crashes — must be an integration issue."
Related Terms
Assertion
An assertion is your test saying 'I DEMAND this is true!'. It's you checking that the result is what you expected.
Integration Test
If a unit test checks one LEGO brick, an integration test checks that two bricks actually snap together correctly.
Jest
Jest is the most popular JavaScript testing framework.
Mock
A mock is a fake version of something your code talks to.
Test Suite
A test suite is just a collection of related tests grouped together.