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 your app and database with Vitest

1m:41s
27m:37s

Testing is one of the most complicated things as a developer. Today, we’re going to make that easy.

In this session, you’ll learn how to test, when to test, how to write tests. And you’ll learn be able to test your application in a way that make sense — and not use TDD (and other non-working, time-consuming methods).

Note

We went a bit too fast when we covered how to test middlewares in this lesson. If you feel don’t get it, don’t worry. Watch the next lesson because we’ll slow down and explain everything step by step.

Source Code

Here’s a link to the Github Repository.

Timestamps

  • 00:00 Introduction of Testing Frameworks
  • 01:00 Installing Vitest
  • 02:00 Running Vitest
  • 03:30 Understanding how Vitest works
  • 04:00 Writing the first test file
  • 05:30 Creating a npm script for easier testing
  • 06.30 Understanding expect and toBe
  • 09:00 Thoughts on TDD
  • 10:46 Figuring out what to test for
  • 13:45 Setting up database for testing
  • 17:22 Testing the createUser function
  • 18:51 Debugging an error
  • 21:20 Figuring out what to test for in createUser
  • 24:00 Checking whether the user is populated into the Database
  • 28:45 Fixing an error in our createUser code
  • 34:00 Testing the login function
  • 38:00 Using Describe to create test a group of functionality
  • 39:00 Naming tests
  • 40:00 Testing for errors
  • 44:00 Checklist mindset for testing
  • 46:00 Summary of what to test
  • 49:00 Testing middlewares
  • 53:00 Building requests, response, and next functions for testing
  • 54:35 Understanding Mocks
  • 55:15 Resetting mocks
  • 56:55 Building a user for testing
  • 59:10 Testing a duplicated user
  • 1:01:09 Fixing another bug in the createUser function
  • 1:09:11 Recap what the bug was about
  • 1:10:01 Testing for a second user
  • 1:11:15 Using Faker to generate fake data for testing
  • 1:15:18 Questions and Answers