Test a Node API with confidence using Jest and supertest — write fast unit tests, integration-test HTTP endpoints, handle asynchronous code correctly, and isolate collaborators with mocks and fixtures. You will finish able to drive an API route through a red-green-refactor cycle and read coverage honestly.
Watch the free preview
Why test, and getting Jest running — free to watch, no account needed.
What you'll learn
- Test a Node API with confidence using Jest and supertest
- Write and organise unit tests with describe, test, expect and the right matchers
- Test asynchronous code correctly with promises and async/await
- Integration-test HTTP endpoints and isolate collaborators with mocks and fixtures
- Drive an API route through a red-green-refactor TDD cycle and read coverage honestly
Syllabus
Jest Fundamentals — the Testing Toolkit
Why test, and getting Jest runningFree preview
describe, test, expect and choosing matchers
Unit Testing & Testing Async Code
Unit testing pure functions and modules
Testing asynchronous code correctly
Integration Testing HTTP APIs
Supertest — testing Express endpoints
Mocks, spies and fixtures
Coverage & the TDD Workflow
Coverage and what it really tells you
Red-green-refactor on an API route
Lab — 10 Exercises & Solutions
Exercises 1–5
Exercises 6–10