Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Real World Node
Lesson Plan
  1. Workshop Recordings
    1. 📹 Understanding Node and Express
    2. 📹 Creating a traditional server
    3. 📹 Building API servers
    4. 📹 Create, Read, Update, and Delete APIs with real databases
    5. 📹 Handling user flows
    6. 📹 Testing your app and database with Vitest
    7. 📹 Testing Middlewares and APIs — including Mocking
    8. 📹 Changing and resetting passwords

📹 Testing Middlewares and APIs — including Mocking

1m:27s
21m:45s

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.

Note

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