This is a huge lesson where we cover three major topics:
- Testing Middlewares
- Testing APIs
- Mocking
The most difficult part about testing Middlewares and APIs is simply setting up the project and understanding how to test them. Of course, it’s going to be easy for you we bring you through the process.
We’re also going to cover Mocking. Mocking is one of the most confusing things about testing for a beginner. But that’s going to be a cinch when you’re learning from us here — because we’ll show you how it works and how to make it work for you.
This session is turned out to contain more complex topics that I originally planned to teach (like Mocking). So you’re getting a bonus into one of the hardest topics that stumps most upcoming developers.
Source Code
Here’s a link to the Github Repository.
Timestamps
- 00:00 Introduction
- 01:35 Recap from previous session
- 02:30 Vitest run vs Vitest watch mode
- 03:30 Why we used buildReq, buildRes, and buildNext
- 09:45 Understanding mocking in detail
- 15:30 Testing the Basic authentication middleware
- 19:00 Mocking the login function
- 26:11 Continuing with testing the Basic authentication middleware
- 34:00 Recap: Testing basic authentication
- 40:44 Testing Bearer authentication
- 41:45 Testing APIs
- 45:50 Litmus test for a server
- 50:20 What to test for in an API
- 51:00 Testing the Create User API
- 1:00:00 Testing the Get User API
- 1:04:04 Simplifying the fetch requests
- 1:07:30 Testing API errors
- 1:13:20 Using match and inline snapshots
- 1:15:26 A small refactor
- 1:18:00 Quick recap of the session
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the workshop or enroll in Magical Dev School.
Unlock this lesson