Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Vitest 50 Drills: TypeScript Unit Testing from the Ground Up
New
2 students

Vitest 50 Drills: TypeScript Unit Testing from the Ground Up

Don't just memorize Jest-style APIs. Master Vitest in 50 drills: mocks, fake timers, fixtures, snapshots, types, CI.
Created byM Sakai
Last updated 7/2026
English

What you'll learn

  • Understand Vitest's execution model and its link to Vite, and explain why TypeScript/ESM tests run zero-config, wielding `globals` and `environment` correctly.
  • Design assertions that convey intent: three equality levels `toBe`/`toEqual`/`toStrictEqual`, asymmetric matchers, and custom matchers via `expect.extend`.
  • Compose fixtures with `test.extend` into a dependency graph, and design test preconditions that balance speed and isolation using `auto` and `scope:"worker"`.
  • Choose among `vi.fn`/`vi.spyOn`/`vi.mock`/`vi.stubGlobal`/`vi.stubEnv` per target, and correctly handle the three-tier clear/reset/restore and ESM hoisting.
  • Test async deterministically without waiting real time: `resolves`/`rejects`, `*Async` fake timers, `vi.waitFor`, `test.concurrent`, and `retry`/`repeats`.
  • Verify temporary-file I/O, in-memory SQLite, and a Hono+zod HTTP API with "real but fast" integration tests, and swap dependencies via dependency injection.
  • Put Vitest-only weapons to work in practice: snapshots, in-source tests, type tests with `expectTypeOf`, and benchmarks with `bench`.
  • Configure a coverage-threshold gate and unit/integration separation via `projects`, and build a locally reproducible mock CI to operationalize your tests.

Course content

12 sections104 lectures7h 1m total length
  • Course Overview7:25
  • How the Course Is Conducted11:10
  • How to Use CodeSandbox0:11
  • Link to codesandbox0:02

Requirements

  • Able to read and write basic JavaScript/TypeScript (variables, functions, classes, `import`/`export`, `async`/`await`). No framework knowledge is needed.
  • A PC with an internet connection and a modern browser (Chrome recommended) is all you need. We use codesandbox, so there is no Node.js install or setup at all.
  • No testing experience required. Even if you've never written a single test, the course is built so you can start from the very first test in Chapter 0.

Description

This course contains the use of artificial intelligence.

I can copy Jest's syntax. But I can't explain why it's written that way. — This course exists to get you out of exactly that state.

Vitest is a test runner that reuses Vite's transform pipeline directly to execute your tests. Once you grasp this single fact, everything connects on one line: why TypeScript runs with zero config, why `vi.mock` takes effect before your imports, why Promises don't resolve under fake timers. This course builds up that "how it works" understanding systematically through 50 hands-on drills.

Learning follows a roadmap of 10 chapters. Chapter 0 nails down Vitest's execution model. Chapter 1 covers the "three levels of equality" (`toBe` / `toEqual` / `toStrictEqual`), asymmetric matchers, and even writing your own custom matchers. Chapter 2 covers data-driven testing with `test.each` / `describe.each` / `test.for`; Chapter 3 covers hook execution order and the dependency graph and scope design of Vitest's fixture mechanism `test.extend`.

Chapter 4 is a full system for mocks. The three-tier reset distinction of `mockClear` / `mockReset` / `mockRestore` that trips up so many learners, and the hoisting behavior of `vi.mock`, are made to click through running code. Chapter 5 conquers async testing end to end: `resolves` / `rejects`, fake timers × Promises, `vi.waitFor`, `test.concurrent`, and `retry` for flaky tests.

From Chapter 6 we turn to real targets. You'll build designs that verify temporary-file I/O, the repository pattern over in-memory SQLite (`node:sqlite`), and HTTP APIs with Hono and zod as "real I/O, but fast and deterministic." Chapter 7's snapshots show how to remove noise with custom serializers; Chapter 8 covers Vitest-only weapons: in-source tests, type tests (`expectTypeOf`), benchmarks (`bench`), and browser mode. The final chapter closes with a coverage-threshold gate, unit/integration separation via `projects`, and a capstone that implements `PriceCalculator` via TDD and builds a mock CI.

Not just becoming able to write tests, but becoming able to design tests. That is the goal of this course.

Who this course is for:

  • JavaScript/TypeScript developers who can copy Jest's syntax but feel they can't explain "why it's written that way."
  • Beginner-to-intermediate learners who want to start frontend/Node.js test automation without getting stuck on environment setup.
  • Engineers considering a move from Jest to Vitest, or already using Vitest but frequently tripping up on mocks and async tests.
  • Those with test-framework experience in other languages (e.g. pytest) who want to port that knowledge to JavaScript/TypeScript by the shortest path.
  • Team leads and tech leads who want to learn test design as a "team safety net," including coverage thresholds and CI pipelines.