JavaScript Unit Testing – The Practical Guide

JavaScript Unit Testing – The Practical Guide

English | MP4 | AVC 1280×720 | AAC 44KHz 2ch | 92 lectures (5h 40m) | 2.22 GB

Learn how to write automated tests (unit & integration tests) for your JavaScript projects with Vitest & Jest.

Automated testing is a key concept in modern (web) development.

Yet it is a concept that can be intimidating at first, hence many developers shy away from diving into testing and adding tests to their projects.

This course will teach you automated unit & integration testing with JavaScript from the ground up. You will learn how tests are written and added to your projects, what should (and should not) be tested and how you can test both simple as well as more complex code.

You will learn about the software and setup required to write automated tests and example projects will be provided as part of the course. It’s a hands-on, practical course, hence you won’t get stuck in theory – instead you’ll be able to learn all key concepts at real examples.

In the course, Vitest will be used as the main testing library & tool. It’s a modern JavaScript test runner and assertion library that provides Jest compatibility. Hence what you’ll learn in this course will help you no matter if you’re working with Vitest or Jest. And the core concepts will apply, no matter which testing setup you’re using at all!

As part of this course, typical testing problems will be defined and solved and common strategies like mocking or working with spies are taught in great detail. This course also does not focus on specific types of JavaScript projects – neither does it focus on any specific library or framework.

Instead, you’ll learn how to automatically test your (vanilla) JavaScript code, no matter if it’s a NodeJS or frontend project. The fundamentals you’ll gain in this course will help you in all your future projects – backend (NodeJS) and frontend (vanilla JS, React, Vue, Angular) alike.

This course will provide you with an extremely solid foundation to build up on, such that you can start adding tests to all your JavaScript projects.

In detail, this course will teach you:

  • What exactly “testing” or “automated testing” is (and why you need it)
  • What “unit testing” is specifically
  • Which tools you need to enable automated unit tests in your projects
  • How to write unit tests
  • How to get started with integration tests
  • How to formulate different expectations (assertions)
  • Which patterns to follow when writing tests
  • How to test asynchronous and synchronous code
  • How to deal with side effects with help of spies & mocks
  • How to apply all these concepts in real projects & examples

What you’ll learn

  • Write and structure unit & integration tests
  • Remove side effects from tests via mocking and spies
  • Work with popular JavaScript test runners and libraries
  • Write good tests and focus on testing core business logic
Table of Contents

Getting Started
1 Welcome To This Course!
2 What Is Testing
3 Unit Testing What & Why
4 Unit vs Integration vs E2E Tests
5 A Quick Note About Test-Driven Development (TDD)
6 About This Course
7 Join Our Learning Community
8 Course Resources & Project Snapshots

Setup & Testing Software
9 Module Introduction
10 Which Tools Are Needed For Testing
11 Jest & Vitest
12 Installing Vitest
13 Course Project Setup

Testing Basics
14 Module Introduction
15 Basic Test File & Project Setup
16 Writing a First Test
17 Running Tests
18 Why Are We Testing
19 The AAA Pattern – Arrange, Act, Assert
20 Keep Your Tests Simple!
21 Defining Behaviors & Fixing Errors In Your Code
22 Demo Writing More Tests
23 Testing For Errors
24 Demo Adding More Tests
25 Testing For Thrown Errors & Error Messages
26 Exercise Problem
27 Exercise Solution
28 Tests With Multiple Assertions (Multiple Expectations)
29 More Practice!
30 Introducing Test Suites
31 Adding Tests To Frontend & Backend Projects
32 Module Summary

Writing Good Tests
33 Module Introduction
34 What To Test & Not To Test
35 Writing Good Tests – An Overview & Summary
36 Only Test One Thing
37 Splitting Functions For Easier Testing & Better Code
38 Refactoring Code
39 Formulating Different Expectations
40 A Word About Code Coverage
41 Module Summary

Integration Tests
42 Module Introduction
43 Introducing Integration Tests
44 Writing an Integration Test & Reasoning
45 Testing For Errors
46 Integration vs Unit Tests Finding the Right Balance

Advanced Testing Concepts
47 Module Introduction
48 toBe() vs toEqual()
49 The Problem With Asynchronous Code
50 Testing Asynchronous Code With Callbacks
51 Testing Asynchronous Code With Promises & async await
52 Returning Promises In Tests
53 Getting Started with Testing Hooks
54 Why Hooks
55 Using Testing Hooks (beforeEach, beforeAll, afterEach, afterAll)
56 Concurrent Tests
57 Concurrency & Default Behavior
58 Module Summary

Mocking & Spies Dealing with Side Effects
59 Module Introduction
60 The Starting Project
61 The Problem With Side Effects & Tests
62 Introducing Spies & Mocks
63 Working with Spies
64 Getting Started with Mocks & Automocking
65 Note on Mocking
66 Notes on Spies
67 Custom Mocking Logic
68 Managing Custom Mock Implementations Globally ( mocks Folder)
69 More Mocking Functionalities
70 Module Summary

More on Mocking & Diving Deeper
71 Module Introduction
72 The Starting Project
73 Refresher Practicing Basic Tests (1)
74 Refresher Practicing Basic Tests (2)
75 Reasons to Mock
76 Mocking Global Values & Functions
77 Mocking Frontend Libraries
78 Test-specific Mocking Logic
79 Mocking In Selected Places
80 Using Local Mock Values
81 Module Summary

Testing & The DOM (Frontend JavaScript Testing)
82 Module Introduction
83 Understanding the Problem
84 Working with Different Testing Environments
85 Setting up a Virtual HTML Page
86 Testing DOM Functionalities
87 DOM Tests & Cleanup Work
88 Finishing Example
89 A Brief Look at the Testing Library Package
90 Module Summary

Course Roundup
91 Course Roundup
92 Bonus Lecture

Homepage