Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Replace databases and APIs with mocks during tests.
Mocking Dependencies 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 Mocking Dependencies example in a small scratch file, then explain what changed and why.