Mocking Techniques in Vitest

1h 30m 36s
English
Paid
October 26, 2024
Let's admit it, mocking can be really confusing. First, you need to understand what exactly to mock. Then, find the right way so it doesn't degrade the quality of your testing. If there are too many mocks, tests lose their meaning. If there are too few, they become fragile. In any case, you spend a lot of effort, and the feeling of usefulness doesn't always come. And this is where Artyom comes to the rescue. For almost a decade, he has been dispelling developers' misconceptions about mocking and is ready to make you a professional in this field.
More

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.

Watch Online Mocking Techniques in Vitest

Join premium to watch
Go to premium
# Title Duration
1 Intro to Mocking Techniques in Vitest 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

Similar courses to Mocking Techniques in Vitest

Namaste Frontend System Design

Namaste Frontend System DesignAkshay Saini (NamasteDev.com)

Duration 72 hours 31 minutes 50 seconds
Software Essentialist

Software EssentialistKhalil Stemmler

Duration 34 hours 6 minutes 47 seconds
Clean Code: Writing Code for Humans

Clean Code: Writing Code for Humans pluralsight

Duration 3 hours 10 minutes 36 seconds
HTMX - The Practical Guide

HTMX - The Practical GuideAcademind Pro

Duration 4 hours 5 minutes
Build Modern Websites with Astro!

Build Modern Websites with Astro!James Q Quick

Duration 7 hours 28 minutes 32 seconds
Animations on the web

Animations on the webEmil Kowalski

Duration 1 hour 47 minutes 41 seconds