Aller au contenu principal
Academind
Tous les cours

Cours Academind Pro

JavaScript Unit Testing - The Practical Guide

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

  • 10 sections · 92 leçons
  • 5 h et 38 min au total
JavaScript Unit Testing - The Practical Guide

À propos de ce cours

You can write JavaScript that works — but the moment you change something, you’re never 100% sure what you just broke. And when testing feels intimidating, it’s easy to keep shipping without the safety net you know you should have.

This course gives you a practical, step-by-step way into automated testing without drowning you in theory. You’ll work with real examples, see typical testing problems defined clearly, and then solve them with repeatable strategies you can bring into any codebase.

By the end, you’ll be able to add reliable unit and integration tests to your own projects, choose what’s worth testing (and what isn’t), and keep tests stable even when your code interacts with the outside world. Whether you’re working on NodeJS or frontend code, you’ll leave with a workflow you can apply immediately.

Ce que vous allez apprendre

You’ll build a testing workflow around Vitest (with Jest-compatible patterns) that you can reuse across NodeJS and frontend JavaScript projects.

  1. 01

    Structure unit tests

    You’ll be able to write unit tests that are easy to read and maintain, using clear patterns for arranging test code and keeping each test focused on one behavior.

  2. 02

    Add integration coverage

    You’ll be able to move beyond isolated units and create integration tests that verify multiple pieces working together, so you can catch issues that only appear when code is combined.

  3. 03

    Mock side effects

    You’ll be able to remove side effects from tests by using mocks, so your test suite stays deterministic even when your code would normally touch external dependencies.

  4. 04

    Use spies effectively

    You’ll be able to work with spies to observe calls and interactions, letting you verify how your code behaves without rewriting the production logic just to make it testable.

  5. 05

    Write strong assertions

    You’ll be able to formulate precise expectations (assertions) that prove the right outcomes, instead of tests that pass for the wrong reasons or fail with unclear messages.

  6. 06

    Test async and sync code

    You’ll be able to test both synchronous and asynchronous JavaScript reliably, so promises, timers, and async flows don’t turn your test suite into a flaky guessing game.

Prérequis

  • Basic JavaScript knowledge is required.

  • No prior testing knowledge is necessary.

À qui s’adresse ce cours

  • JavaScript developers

    You’re building projects in JavaScript and want the confidence of automated tests, but you’re not sure how to start or how to structure tests that stay maintainable.

  • Testing-avoidant developers

    You’ve always found automated testing intimidating, so you’ve postponed it — this course gives you a clear, practical path that makes testing feel approachable.

  • Frontend or NodeJS builders

    You work on frontend code or NodeJS code and want a testing foundation that isn’t tied to one framework, so you can apply it across different kinds of projects.

Programme

Découvrez la structure et le rythme de ce cours avant de commencer.

  1. 1Getting Started8 leçons · 24 min
    1. 01Welcome To This Course!0:54 min
    2. 02What Is Testing?4:41 min
    3. 03Unit Testing: What & Why?4:33 min
    4. 04Unit vs Integration vs E2E Tests5:51 min
    5. 05A Quick Note About Test-Driven Development (TDD)1:35 min
    6. 06About This Course6:42 min
    7. 07Join Our Learning Community0:00 min
    8. 08Course Resources & Project Snapshots0:00 min
  2. 2Setup & Testing Software5 leçons · 24 min
    1. 01Module Introduction1:09 min
    2. 02Which Tools Are Needed For Testing?6:27 min
    3. 03Jest & Vitest6:56 min
    4. 04Installing Vitest1:36 min
    5. 05Course Project Setup7:59 min
  3. 3Testing Basics19 leçons · 1 h et 19 min
    1. 01Module Introduction1:20 min
    2. 02Basic Test File & Project Setup7:04 min
    3. 03Writing a First Test6:54 min
    4. 04Running Tests4:18 min
    5. 05Why Are We Testing?3:02 min
    6. 06The AAA Pattern - Arrange, Act, Assert4:36 min
    7. 07Keep Your Tests Simple!1:34 min
    8. 08Defining Behaviors & Fixing Errors In Your Code7:38 min
    9. 09Demo: Writing More Tests4:37 min
    10. 10Testing For Errors4:14 min
    11. 11Demo: Adding More Tests3:29 min
    12. 12Testing For Thrown Errors & Error Messages4:59 min
    13. 13Exercise: Problem1:44 min
    14. 14Exercise: Solution4:47 min
    15. 15Tests With Multiple Assertions (Multiple Expectations)5:18 min
    16. 16More Practice!2:55 min
    17. 17Introducing Test Suites4:39 min
    18. 18Adding Tests To Frontend & Backend Projects3:36 min
    19. 19Module Summary2:22 min
  4. 4Writing Good Tests9 leçons · 37 min
    1. 01Module Introduction1:25 min
    2. 02What To Test & Not To Test6:04 min
    3. 03Writing Good Tests - An Overview & Summary4:36 min
    4. 04Only Test "One Thing"2:02 min
    5. 05Splitting Functions For Easier Testing & Better Code5:01 min
    6. 06Refactoring Code10:13 min
    7. 07Formulating Different Expectations6:07 min
    8. 08A Word About Code Coverage0:00 min
    9. 09Module Summary2:01 min
  5. 5Integration Tests5 leçons · 15 min
    1. 01Module Introduction0:57 min
    2. 02Introducing Integration Tests2:23 min
    3. 03Writing an Integration Test & Reasoning5:51 min
    4. 04Testing For Errors2:28 min
    5. 05Integration vs Unit Tests: Finding the Right Balance3:25 min
  6. 6Advanced Testing Concepts12 leçons · 38 min
    1. 01Module Introduction1:06 min
    2. 02toBe() vs toEqual()4:21 min
    3. 03The Problem With Asynchronous Code6:13 min
    4. 04Testing Asynchronous Code With Callbacks5:02 min
    5. 05Testing Asynchronous Code With Promises & async / await4:32 min
    6. 06Returning Promises In Tests0:00 min
    7. 07Getting Started with "Testing Hooks"1:42 min
    8. 08Why Hooks?4:39 min
    9. 09Using Testing Hooks (beforeEach, beforeAll, afterEach, afterAll)6:13 min
    10. 10Concurrent Tests2:14 min
    11. 11Concurrency & Default Behavior0:00 min
    12. 12Module Summary1:48 min
  7. 7Mocking & Spies: Dealing with Side Effects12 leçons · 45 min
    1. 01Module Introduction1:03 min
    2. 02The Starting Project4:11 min
    3. 03The Problem With Side Effects & Tests6:24 min
    4. 04Introducing Spies & Mocks2:07 min
    5. 05Working with Spies5:13 min
    6. 06Getting Started with Mocks & Automocking5:18 min
    7. 07Note on Mocking2:18 min
    8. 08Notes on Spies1:30 min
    9. 09Custom Mocking Logic7:51 min
    10. 10Managing Custom Mock Implementations Globally (__mocks__ Folder)6:11 min
    11. 11More Mocking Functionalities1:34 min
    12. 12Module Summary1:00 min
  8. 8More on Mocking & Diving Deeper11 leçons · 46 min
    1. 01Module Introduction1:04 min
    2. 02The Starting Project3:02 min
    3. 03Refresher: Practicing Basic Tests (1)6:25 min
    4. 04Refresher: Practicing Basic Tests (2)4:43 min
    5. 05Reasons to Mock2:11 min
    6. 06Mocking Global Values & Functions8:13 min
    7. 07Mocking Frontend Libraries0:00 min
    8. 08Test-specific Mocking Logic6:59 min
    9. 09Mocking In Selected Places5:21 min
    10. 10Using Local Mock Values7:01 min
    11. 11Module Summary1:16 min
  9. 9Testing & The DOM (Frontend JavaScript Testing)9 leçons · 25 min
    1. 01Module Introduction1:14 min
    2. 02Understanding the Problem3:58 min
    3. 03Working with Different Testing Environments3:42 min
    4. 04Setting up a Virtual HTML Page5:05 min
    5. 05Testing DOM Functionalities2:58 min
    6. 06DOM Tests & Cleanup Work3:12 min
    7. 07Finishing Example1:32 min
    8. 08A Brief Look at the "Testing Library" Package1:53 min
    9. 09Module Summary1:08 min
  10. 10Course Roundup2 leçons · 4 min
    1. 01Course Roundup4:10 min
    2. 02Bonus: More Courses & Content0:00 min

Prêt à commencer ?

Achetez ce cours sur Academind Pro, ou obtenez tous les cours avec All Access sur Academind Infinite.

Black Friday : un an d’All Access pour 249 $US 249 $US · seulement jusqu’au Profitez de l’offre
  • Ce cours sur Academind Pro

    69 $USpaiement unique

    TVA incluse · Satisfait ou remboursé pendant 30 jours

    • Accès à vie à ce cours
    • Toutes les futures mises à jour de ce cours
    • Ressources téléchargeables, code et un certificat
    Acheter JS Unit Testing
  • All Access sur Academind Infinite

    25 $USpar mois

    ou 249 $US 249 $US par anÉconomisez 17 %

    • Tous les cours, avec toutes leurs fonctionnalités
    • Les nouveaux cours dès leur sortie
    • Votre tuteur, avec toutes ses fonctionnalités
    Obtenir All Access

All Access inclut aussi tous les cours Academind Pro.

Academind Pro et Academind Infinite

Deux plateformes distinctes, chacune avec ses propres cours et sa propre connexion.

Academind Pro

Notre plateforme de cours d’origine, sur pro.academind.com. Votre abonnement Pro et les cours que vous y avez achetés restent sur Pro.

Se connecter à Academind Pro

Academind Infinite

Notre nouvelle plateforme pensée pour l’IA. Les membres Pro se connectent avec leur compte Pro, et l’offre Pro All Access inclut Infinite : tous les cours leur sont ouverts.

Se connecter à Academind Infinite

Vous aviez un compte Pro ou avez acheté un cours sur Pro ?

Tous les cours Pro ne sont pas passés sur Infinite, seulement ceux-ci. Choisissez le vôtre pour le voir sur Infinite.