Web Development · WDC-121

TDD with Node.js and TypeScript

TDD with Node.js and TypeScript is a hands-on course in test-driven backend development with Vitest, from the red-green-refactor cycle and test doubles to API tests with Supertest, integration tests against real PostgreSQL with Testcontainers and mutation testing. It suits backend developers, full-stack developers and tech leads, and you leave with a sample API, its test suite and a CI pipeline.

Updated
From 7,650 THB / person 8,500 −10% excl. VAT 7% · group rates available
PDFDownload the course outline
  • Duration18 hours · 3 days
  • FormatOnsite / live online
  • Next roundOn request
  • CertificateIncluded

Course overview

Development teams now ship software much faster, thanks to modern tooling and AI that helps write code. That speed brings risk: bugs can hide in the code, a change in one place quietly breaks another, and tests written after the fact often miss the behaviour that matters most. Teams need a way of working that builds confidence in quality from the very first line of code.

This course trains the red-green-refactor cycle systematically on Node.js 24 LTS and TypeScript, with Vitest as the main tool. It starts with short katas, moves on to a REST API with Express 5 and Supertest, tests against real PostgreSQL with Testcontainers, measures test quality with coverage and mutation testing, and brings it all into a CI pipeline, using a single project, the ParcelPoint Shipment API, developed test-first throughout the course. (3 days, 6 hours per day, 18 hours in total, Intermediate level.)

What you’ll gain

  • Understand the principles and benefits of test-driven development and make the red-green-refactor cycle a habit
  • Set up a Node.js and TypeScript project for testing with Vitest correctly
  • Write unit tests that are readable, maintainable and test behaviour rather than internal details
  • Choose the right test double (stub, mock, spy, fake) for each situation
  • Develop REST APIs test-first and test HTTP endpoints with Supertest
  • Write integration tests against a real database with Testcontainers
  • Measure the quality of a test suite with coverage and mutation testing
  • Bring the test suite into a CI pipeline and define a quality gate for the team

Who this course is for

  • Backend developers who use Node.js and TypeScript in their daily work
  • Full-stack developers who want to raise the quality of their server-side code
  • Tech leads who want to set a testing standard for their team
  • QA engineers who want to work closely with developers at the unit and integration test level
  • Teams that use AI to help write code and want tests as a specification they can verify

Prerequisites

  • Working knowledge of JavaScript or TypeScript, such as functions, classes and async/await
  • Experience building REST APIs with Node.js, for example with Express
  • A basic grasp of SQL and relational databases, and the ability to use Git, npm and the command line
  • No prior experience of writing tests or using Vitest is needed; testing basics are covered from the start

Curriculum

Course Details

This course builds on Software Testing Foundation and Basic Node.js and focuses on backend developers writing tests before code at the unit and integration level, where testing pays off most for code quality. End-to-end testing of web pages is covered in Playwright End-to-End Test Automation. It runs for 3 days, 6 hours per day (18 hours in total, 09:00-16:00), as a continuous workshop on

a single project, the ParcelPoint Shipment API, using generated data only. Express 5 is the main example, and the same approach works with Fastify, Hono or NestJS. All tools are open source and run on the learner's own laptop with Docker, and the CI labs use the learner's own GitHub or GitLab account. Learners take home the source code, the test suite and CI pipeline files to use as a team template.

Day 1 TDD Fundamentals with Vitest

Section 1: Principles of Test-Driven Development

  • The problems with writing tests afterwards and the benefits of writing them first
  • The red-green-refactor cycle and the three rules of TDD
  • The testing pyramid (unit, integration, end-to-end) and the testing trophy
  • TDD when AI helps write code: tests as a specification you can verify
  • Lab: analyse untested code and write a first test that defines the behaviour you want

Section 2: Setting Up a Node.js and TypeScript Project

  • Node.js 24 LTS and running TypeScript with type stripping
  • TypeScript 7 (the native compiler) for type checking, and tools that still need TypeScript 6
  • Configuring tsconfig and ES modules
  • Installing and configuring Vitest, compared with node:test
  • Lab: create a starter project that runs tests and type checks with a single command

Section 3: Writing Good Unit Tests

  • The describe, test and expect structure
  • The Arrange-Act-Assert pattern and naming tests after behaviour
  • Common matchers, and testing exceptions and async functions
  • Parameterised tests with test.each to cut duplication
  • Lab: rework hard-to-read tests so they are short, clear and not brittle

Section 4: TDD Kata Practice

  • Practise the TDD cycle on short exercises such as String Calculator
  • Fake It, Triangulation and Obvious Implementation
  • Refactoring safely with tests as a safety net
  • Lab: do a kata in pairs with ping-pong pairing, swapping between writing tests and writing code

Section 5: Workshop Day 1: ParcelPoint Domain Logic

  • Calculate shipping costs by weight and zone test-first
  • Apply discount coupons with their conditions and edge cases
  • A state machine for parcel status: Created, Picked Up, In Transit, Delivered and Cancelled
  • Workshop: refactor the domain logic for readability while every test still passes
Day 2 TDD for REST APIs and Test Doubles

Section 6: Designing Code for Testability

  • Splitting code into route, service and repository layers
  • Simple dependency injection without a framework
  • An introduction to ports and adapters (hexagonal architecture)
  • Lab: extract a service's dependencies behind interfaces so it can be tested

Section 7: Test Doubles

  • The differences between dummies, stubs, spies, mocks and fakes
  • Using vi.fn, vi.spyOn and vi.mock
  • Controlling time with fake timers
  • The dangers of over-mocking
  • Lab: test the customer notification service with a mock and test expiry times with fake timers

Section 8: TDD with REST APIs

  • Outside-in TDD, from the endpoint down to the service
  • Testing Express 5 with Supertest: status codes, headers and bodies
  • Validating input with Zod and testing validation errors
  • Testing error-handling middleware
  • Lab: build the create-parcel endpoint, always writing the Supertest test first

Section 9: Testing Authentication and Authorisation

  • Testing endpoints that need a token, for both allowed and denied cases
  • Testing role-based access
  • Building test helpers for each user role to reduce duplication
  • Lab: add a rule that only staff can cancel a parcel, starting from a failing test

Section 10: Workshop Day 2: The ParcelPoint REST API

  • Endpoints to create, search, update the status of and cancel parcels, with a test written before each one
  • An in-memory fake repository in place of the database
  • A mock for the customer notification service
  • Workshop: review the test suite together and fix tests that are too tied to internal details
Day 3 Integration Testing, Test Quality, CI and Master Workshop

Section 11: Integration Testing with Testcontainers

  • The limits of mocking the database and why you need to test against a real one
  • Using @testcontainers/postgresql to start a temporary PostgreSQL instance
  • Migrating the schema and preparing test fixtures
  • Isolating data between tests and cutting run time with global setup
  • Lab: run repository tests against real PostgreSQL in a container

Section 12: Code Coverage

  • Line, branch and function coverage with Vitest coverage (V8)
  • Setting coverage thresholds that suit the project
  • The limits of coverage as a measure of test quality
  • Lab: read the coverage report and add tests for untested branches

Section 13: Mutation Testing with StrykerJS

  • How mutation testing works and what the mutation score means
  • Setting up StrykerJS with the Vitest runner
  • Analysing surviving mutants and improving the tests
  • Lab: raise the mutation score of the domain logic by strengthening weak assertions

Section 14: Bringing TDD into CI and Team Practice

  • Running unit and integration tests in CI with GitHub Actions or GitLab CI
  • A quality gate based on tests, coverage and type checks
  • Applying TDD to legacy code with characterisation tests
  • Code reviews that give tests proper attention
  • Lab: set up a pipeline that blocks merging when tests fail

Section 15: Master Workshop: A Production-ready ParcelPoint

  • Replace the fake repository with real PostgreSQL through Testcontainers and write integration tests for the main flows
  • Run coverage and StrykerJS to find weak tests and improve them
  • Add an express delivery fee feature test-first, from the first test to the endpoint
  • Set up a CI pipeline with a quality gate, then present the result and review the code together

Schedule & training options

For individuals — public rounds

No public rounds are open right now. Join the waiting list and we will contact you first when the next round opens, or ask us on LINE. Or call 02-570-8449 or 088-807-9770

For organisations — in-house / private

  • Tailor the content to your team’s tools and projects
  • Your dates, at your office or live online
  • Quotation with tax ID for procurement
Corporate training quote

Instructors

Frequently asked questions

How does this course differ from Software Testing Foundation and Playwright End-to-End Test Automation?

Software Testing Foundation lays a broad foundation in testing principles, and Playwright End-to-End Test Automation focuses on testing web pages by simulating users. This course takes the backend developer's view: writing tests before code on Node.js and TypeScript at the unit and integration level, from domain logic and REST APIs with Supertest to real databases with Testcontainers, mutation testing and a CI quality gate. The three courses complement each other.

Do I need to have written tests before?

No. Day 1 covers unit testing with Vitest from the start. You should, however, be able to write JavaScript or TypeScript at a working level and have built REST APIs with Node.js before.

I use Fastify, Hono or NestJS at work. Will this still apply?

Yes. Express 5 is the main example because it is the most familiar, but TDD itself, layering, test doubles, Testcontainers and mutation testing work the same way with other frameworks. The instructor points out what differs when you apply them to Fastify, Hono or NestJS.

What laptop and accounts do I need?

A laptop with at least 8 GB of RAM (16 GB recommended) with Node.js 24 LTS, Git, VS Code and a working Docker Desktop (with WSL2 on Windows), since Testcontainers needs Docker. You also need your own GitHub or GitLab account for the CI pipeline labs.

What is mutation testing, and why is coverage alone not enough?

Coverage only shows which lines ran during the tests, not whether the tests actually check the results. Mutation testing with StrykerJS changes the code automatically, one small change at a time, and checks whether the tests catch each change, which points you straight at weak tests to improve.

Which tool versions does the course use?

The course is based on Node.js 24 LTS, TypeScript 7 with its native compiler, Vitest and Express 5, the current releases, and explains where some tools still need TypeScript 6. JavaScript tooling releases often, so the content follows the latest versions on the training day.