Mocking Techniques in Vitest
Mocking Techniques in Vitest is a 48-lesson 1 hour 30 minutes self-paced course by Artem Zakharchenko. Let's admit it, mocking can be really confusing.
Course facts
- Lessons
- 48
- Duration
- 1 hour 30 minutes
- Language
- English
- Instructor
- Artem Zakharchenko
- Price
- Premium
What you will learn:
In this practical workshop, you will learn:
- The purpose of mocking;
- What and when to mock;
- How to write mocks that are beneficial rather than a maintenance burden;
- How to separate mocks from implementation details;
- How to ensure type safety in mocks;
- And all the mocking techniques you need to test your code!
By solving real-world tasks using the Vitest framework, you will gain a complete understanding of mocking and finally make it a useful tool in your testing arsenal.
Workshop Structure: The workshop consists of 6 blocks of exercises dedicated to different mocking techniques for various data types.
Boundaries
Understand what mocking really is and how it helps create test boundaries. Learn how each mock affects the code being tested with clear examples.
Mocking Functions
Functions are at the core of JavaScript logic. Learn to mock functions for effective testing of input and output data. Create mocks for functions, track their calls, and configure behavior in the code being tested.
Mocking Date and Time
Eliminate side effects of changing date and time in tests. Learn how to “freeze” time and mock time-dependent code to ensure stable test results.
Mocking Global Variables
Explore how to mock implicit dependencies without disruption. Learn to mock global values, methods, and environment variables, creating the perfect testing environment.
Mocking Network Requests
Gain control over network requests and reliably test client-side code. Intercept requests and mock responses using Mock Service Worker, simulating various network scenarios.
Mocking Modules
Understand when to use module mocking and explore alternative techniques. Learn to safely mock modules using Vitest's built-in APIs.
Who this workshop is for: This workshop is intended for all developers, both newcomers to automated testing and those who have been writing tests for years. If you are unsure when to introduce mocks into your test suite or how to do it without having to redo it the next day, this workshop is designed especially for you.
Additional
Who teaches Mocking Techniques in Vitest? Artem Zakharchenko
Artem Zakharchenko is a Ukrainian software engineer best known as the creator of Mock Service Worker (MSW) — the de-facto standard for API mocking in modern JavaScript test suites — and as a lead instructor on the EpicWeb.dev testing track alongside Kent C. Dodds.
His CourseFlix listing carries four Artem Zakharchenko courses: Testing Fundamentals (EpicWeb), Mocking Techniques in Vitest, Advanced Vitest Patterns, and React Component Testing with Vitest. Material is paid and aimed at JavaScript developers who want to make testing a first-class part of their workflow rather than an afterthought.
What lessons are included in Mocking Techniques in Vitest?
| # | Lesson Title | Duration | Access |
|---|---|---|---|
| 1 | Intro to Mocking Techniques in Vitest Demo | 02:48 | |
| 2 | Intro to Boundaries | 00:43 | |
| 3 | Test boundaries _Problem | 01:40 | |
| 4 | Test boundaries _solution | 02:27 | |
| 5 | Recap of Boundaries | 00:18 | |
| 6 | Intro to Functions | 00:42 | |
| 7 | Mock functions _Problem | 01:57 | |
| 8 | Mock functions _solution | 02:52 | |
| 9 | Spies _Problem | 00:54 | |
| 10 | Spies _solution | 02:22 | |
| 11 | Mock implementation _Problem | 01:32 | |
| 12 | Mock implementation _solution | 03:25 | |
| 13 | Recap of Functions | 00:22 | |
| 14 | Intro to Date and time _solution | 00:59 | |
| 15 | Date and time _Problem | 01:04 | |
| 16 | Date and time _solution | 02:15 | |
| 17 | Timers _Problem | 02:01 | |
| 18 | Timers _solution | 02:47 | |
| 19 | Ticks and tasks _Problem | 02:16 | |
| 20 | Ticks and tasks _solution | 02:15 | |
| 21 | Recap of Date and time | 00:19 | |
| 22 | Intro to Globals | 01:16 | |
| 23 | Global methods _Problem | 00:38 | |
| 24 | Global methods _solution | 02:20 | |
| 25 | Global values _Problem | 01:25 | |
| 26 | Global values _solution | 02:28 | |
| 27 | Environment variables _Problem | 01:22 | |
| 28 | Environment variables _solution | 03:49 | |
| 29 | Recap of Globals | 00:25 | |
| 30 | Intro to Network | 02:17 | |
| 31 | Set up MSW _Problem | 05:02 | |
| 32 | Set up MSW _solution | 01:28 | |
| 33 | Mock responses _Problem | 01:05 | |
| 34 | Mock responses _solution | 02:25 | |
| 35 | Error responses _Problem | 01:40 | |
| 36 | Error responses _solution | 02:59 | |
| 37 | Network errors _Problem | 00:59 | |
| 38 | Network errors _solution | 01:49 | |
| 39 | Response delay _Problem | 00:59 | |
| 40 | Response delay _solution | 02:30 | |
| 41 | Recap of Network | 00:41 | |
| 42 | Intro to Modules | 00:57 | |
| 43 | Dependency injection _Problem | 03:28 | |
| 44 | Dependency injection _solution | 03:45 | |
| 45 | Private side effects _Problem | 02:11 | |
| 46 | Private side effects _solution | 05:28 | |
| 47 | Recap of Modules | 00:31 | |
| 48 | Mocking Techniques in Vitest Outro | 00:41 |
Get instant access to all 47 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.
Learn more about subscriptionWhat courses are similar to Mocking Techniques in Vitest?
UpdatedScalable TDD & Testing
By: Logic RoomFramework-independent TDD techniques for JavaScript UI engineers, aimed at faster development cycles and more reliable code.2h 56m
Updated 2y agoPHPUnit: Testing with a Bite
By: KnpUniversityIt's Friday night... it's stormy... the office is empty... and you're deploying fresh code to production. Suddenly, an alarm! What!? The fences are down!? The d28m
Updated 2y agoGatling Fundamentals for Stress, Load & Performance Testing
By: UdemyIn this course, you will learn the fundamentals of using the Gatling stress testing tool - an extremely powerful, open-source performance testing tool in heavy4h 42m
Updated 3mo agoReact End-to-End Testing with Playwright
By: Artem ZakharchenkoThe course will help you master end-to-end testing of React with Playwright, set up stable E2E processes, and implement a reliable architecture for automated2h 16m
UpdatedAdvanced Vitest Patterns
By: Artem ZakharchenkoGo beyond basic Vitest usage: custom environments, fixtures, matchers, and test organization for large, complex codebases.1h 43m
Updated 6mo agoTDD & BDD - Design Through Testing
By: Dave FarleyLearn testing as a software design tool with a TDD and BDD course. Discover how to reduce errors and improve code with tests.5h 42m
More courses by Artem Zakharchenko
Updated 3mo agoReact End-to-End Testing with Playwright
The course will help you master end-to-end testing of React with Playwright, set up stable E2E processes, and implement a reliable architecture for automated2h 16m
UpdatedAdvanced Vitest Patterns
Go beyond basic Vitest usage: custom environments, fixtures, matchers, and test organization for large, complex codebases.1h 43m
UpdatedReact Component Testing with Vitest
Test React components inside a real browser with Vitest Browser Mode, migrating your test suite away from JSDOM's limits.1h 38m
Updated 2y agoTesting Fundamentals [EpicWeb]
In this workshop, Artem Zakharchenko, testing expert and creator of the Mock Service Worker API mocking library, will guide you through creating your own versio5h 16m