Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Test controllers and services in isolation.
Unit Testing with Jest is easiest to learn by reading the example, changing it, and observing the result.
import { createLesson } from '../services/lessons.js';
test('createLesson rejects a short title', async () => {
await expect(createLesson({ title: 'a' }))
.rejects.toThrow('title');
});
test('createLesson returns a slug', async () => {
const lesson = await createLesson({ title: 'Express Routing' });
expect(lesson.slug).toBe('express-routing');
});Practice the Unit Testing with Jest example in a small scratch file, then explain what changed and why.