M. Kodirov

STAGE 05 / LESSON 05

Unit and integration tests

Different tests give confidence at different boundaries.

THE IDEA

Understand it.

A unit test checks a small behavior in isolation. An integration test checks that parts work together, such as an API handler and a test database. Both should verify meaningful behavior rather than only repeating implementation details.

Jest and Vitest are common JavaScript test tools. Use one that fits the project, keep tests deterministic, and include error cases as well as the happy path.

SEE IT IN CONTEXT

A small behavior test

import { expect, test } from "vitest";
import { countCompleted } from "./tasks";

test("counts completed tasks", () => {
  const tasks = [{ done: true }, { done: false }];
  expect(countCompleted(tasks)).toBe(1);
});

This assumes a countCompleted function in the tasks module. The test checks its result rather than repeating its implementation.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitHub

Public documentation checked November 2026

Test component behavior

Primer React's contributor guide describes Vitest and Testing Library tests for user-facing component behavior.

  1. Render component
  2. Simulate interaction
  3. Assert visible behavior

What to learn: A focused test can verify behavior without depending on a full deployed website.

Read the source: Primer React testing guide

Spotify

Spotify engineering, 2019

Tests for shared web libraries

Spotify described web-scripts, a tool for building JavaScript libraries, including a Jest-based test setup.

  1. Web library
  2. Jest test setup
  3. Test results

What to learn: Automated library tests give feedback before a library is published; the article is about this tooling, not all Spotify tests.

Read the source: Spotify web-scripts

TRY IT YOURSELF

Practice.

Which test would reveal that your API and database disagree about a required column?

Show one possible answer

An integration test that exercises the API against an appropriately prepared test database can reveal that mismatch.

GO DEEPER

Official references.