Complete Course
Unit Testing with Jest
Write the tests closest to the code: Learn Jest, from your first expect to async code, mocks, fake timers, snapshots, and coverage, with test design that finds real bugs and a CI pipeline that fails on them.
~4 hours of content
Course Content
13 comprehensive lessons covering everything you need to know
Introduction
Introduction
Course Structure
Learn how the course is organized and make the most of the content.
Introduction
Prerequisites
Systems and knowledge required to complete the course.
Introduction
Getting to know the code under test
Meet the Bookshelf, the lending rules of a small library, and the README that specifies them.
Lesson
Lesson 1Fork, clone, and install Jest
Fork and clone the repository, install Jest, and read your first (empty) test run.
Your first tests
Lesson
Lesson 2Your first unit test
Write a test with describe, test, and expect, run it, and learn to read a failure.
Lesson
Lesson 3Matchers that matter
Pick the matcher that states the rule, and stop truthiness matchers from hiding bugs.
Lesson
Lesson 4Testing errors
Check that code throws the right error, with the right message, for the right reason.
Lesson
Lesson 5Designing test cases
Turn equivalence classes and boundaries into a test.each table, and let it find a bug.
Organizing tests and state
Lesson
Lesson 6Setup, teardown, and isolation
Use hooks to give every test a fresh start, and catch tests that pass only in one order.
Async code and test doubles
Lesson
Lesson 7Asynchronous code
Test promises with async and await, and catch the forgotten await that makes a test lie.
Lesson
Lesson 8Test doubles and jest.fn()
Tell stubs, spies, mocks, and fakes apart, and replace a dependency with jest.fn().
Lesson
Lesson 9Mocking modules
Mock a module the code requires directly, and see what over-mocking costs.
Lesson
Lesson 10Controlling time and randomness
Freeze the clock, fast-forward timers, and pin Math.random() to test its two ends.
Snapshots, coverage, and CI
Lesson
Lesson 11Snapshot testing
Use snapshots for stable output, and keep them from becoming a rubber stamp.
Lesson
Lesson 12Code coverage
Measure coverage, set a threshold, and find the rule your suite runs but never checks.
Lesson
Lesson 13Running your tests on GitHub Actions
Run the suite on every push, and prove the build goes red on a failing test or a coverage drop.
Bonus & Conclusion
Bonus
Bonus: Jest, Vitest, or node:test?
The same tests in three runners: what transfers unchanged, what changes, and how to choose.
Bonus
Bonus: Unit tests with AI
Draft unit tests with an AI assistant, and judge them against the rules before trusting them.
Conclusion
Congratulations!
You've completed the Unit Testing with Jest course!