How to Mock a REST API Server for Testing with Jest & React Testing Library
Dave Gray
@davegrayteachescodeAbout
Web Development tutorials with full courses on HTML, CSS, JavaScript, React, Node.js and more! My goal is to help you learn how to build the web. Teaching helps me learn, too. I work full-time as a Solutions Architect / Developer and part-time as a university web dev instructor. Thank you for subscribing, supporting my channel and sharing the videos you think may help others. Keep striving for progress over perfection. And a little progress every day goes a very long way. Milestones: July 20, 2020 - 1st video Jan 1, 2021 - 1k subs April 2021 - 4k watch hours Nov 2021 - 10k subs Jan 21, 2022 - Video at 100k views Feb 16, 2022 - 100k watch hours Feb 19, 2022 - 1m views Dec 13, 2022 - 100k subs Dec 2022 - Over 1m views in 1 month April 7, 2023 - 10m views May 26, 2023 - 1m watch hours Sept 22, 2023 - Video at 1m views Dec 25, 2023 - 250k subs
Latest Posts
Video Description
Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap Learn how to mock a Rest API Server for testing with Jest & React Testing Library. In this video, we will mock a REST API Server with MSW and write async unit and integration tests for a Next.js app. 💖 Support me on Patreon ➜ https://patreon.com/davegray ⭐ Become a full-stack web dev with Zero To Mastery Courses: - Complete Next.js Developer: https://bit.ly/CompNextJSDev - Advanced React: https://bit.ly/AdvReactDev - Junior to Senior Dev Roadmap: https://bit.ly/WebDevRoadmap-JrtoSr 🚩 Subscribe ➜ https://bit.ly/3nGHmNn 📬 Course Updates ➜ https://courses.davegray.codes/ ❓ Questions - Please post them to my Discord ➜ https://discord.gg/neKghyefqh ☕ Buy Me A Coffee ➜ https://www.buymeacoffee.com/davegray 👇 Follow Me On Social Media: GitHub: https://github.com/gitdagray Twitter: https://twitter.com/yesdavidgray LinkedIn: https://www.linkedin.com/in/davidagray/ 🔗 Starter Source Code: https://github.com/gitdagray/next-testing-example-app 🔗 Completed Source Code: https://github.com/gitdagray/nextjs-async-testing 📺 "Testing Your Code" playlist: https://www.youtube.com/playlist?list=PL0Zuz27SZ-6NTWVG8eM7Dt43vvzulnIbK How to Mock a REST API Server for Testing with Jest & React Testing Library (00:00) Intro (00:14) Welcome (00:38) Prerequisites & Starter Code (01:00) Lesson Goal (01:07) Adding Dependencies (02:39) Mock REST API Server Setup (08:57) Async Unit Testing (13:38) Modify the Server Response for a test (16:18) Completing the Mock Endpoint handlers (19:02) Completing the CRUD Unit Tests (23:18) Adding the Async CRUD functions to the app (30:11) Adding New & Updating Integration Tests (41:14) Unit Test Update (43:27) Wrap-up 📚 Tutorial References: 🔗 Next.js Official Site: https://nextjs.org/ 🔗 React Testing Library: https://testing-library.com/docs/react-testing-library/intro 🔗 Jest: https://jestjs.io/ 🔗 TypeScript: https://www.typescriptlang.org/ 🔗 MSW: https://mswjs.io/ 🔗 MSW on npm: https://www.npmjs.com/package/msw Was this tutorial about how to create a Mock REST API Server and async testing helpful? If so, please share. Let me know your thoughts in the comments. #mock #rest #api
Upgrade Your Gaming Audio
AI-recommended products based on this video

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech K400 Plus Wireless Touch TV Keyboard With Easy Media Control and Built-in Touchpad, HTPC Keyboard for PC-connected TV, Windows, Android, Chrome OS, Laptop, Tablet - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

New SteelSeries Arctis Nova Pro for Xbox Multi-System Gaming Headset - Premium Hi-Fi Drivers - Hi-Res Audio - 360° Spatial - GameDAC Gen 2 - Quad-DAC - ClearCast Gen 2 Mic - Xbox, PC, PS5/PS4, Switch

HyperX Cloud II - Gaming Headset, 7.1 Surround Sound, Memory Foam Ear Pads, Durable Aluminum Frame, Detachable Microphone, Works with PC, PS5, PS4, Xbox Series X|S, Xbox One – Red

Sony WH-CH720N Noise Cancelling Wireless Headphones Bluetooth Over The Ear Headset with Microphone and Alexa Voice Control, Black

Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

230W Charger Compatible with Razer Blade 14” 15” 16" 17” (2025-2018) RZ09 RTX-3060/3070/3080/4060/4070 Gaming Laptop RC30-0530 RC30-0238 RC30-0248 Replacement Power Adapter

HyperX CloudX Stinger 2 Core - Gaming Headset for Xbox, Lightweight Over-Ear headsets with mic, Swivel-to-Mute Function, 40mm Drivers - White

New SteelSeries Arctis Nova Pro for Xbox Multi-System Gaming Headset - Premium Hi-Fi Drivers - Hi-Res Audio - 360° Spatial - GameDAC Gen 2 - Quad-DAC - ClearCast Gen 2 Mic - Xbox, PC, PS5/PS4, Switch

NEW SteelSeries Arctis Nova 3 Multi-Platform Gaming Headset - Signature Arctis Sound - ClearCast Gen 2 Mic - PC, PS5/PS4, Xbox Series X|S, Switch, Mobile




















