Zum Hauptinhalt springen
Academind
Alle Kurse

Academind-Pro-Kurs

JavaScript Unit Testing - The Practical Guide

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

  • 10 Abschnitte · 92 Lektionen
  • 5 Std., 38 Min. insgesamt
JavaScript Unit Testing - The Practical Guide

Über diesen Kurs

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.

Was du lernst

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.

Voraussetzungen

  • Basic JavaScript knowledge is required.

  • No prior testing knowledge is necessary.

Für wen dieser Kurs ist

  • 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.

Lehrplan

Sieh dir Aufbau und Tempo dieses Kurses an, bevor du startest.

  1. 1Getting Started8 Lektionen · 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 Lektionen · 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 Lektionen · 1 Std., 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 Lektionen · 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 Lektionen · 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 Lektionen · 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 Lektionen · 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 Lektionen · 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 Lektionen · 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 Lektionen · 4 Min.
    1. 01Course Roundup4:10 Min.
    2. 02Bonus: More Courses & Content0:00 Min.

Bereit loszulegen?

Kaufe diesen Kurs auf Academind Pro oder hol dir mit All Access auf Academind Infinite alle Kurse.

Black Friday: ein Jahr All Access für 249 $ 249 $ · nur bis Angebot sichern
  • Dieser Kurs auf Academind Pro

    69 $einmalig

    Inkl. MwSt. · 30 Tage Geld-zurück-Garantie

    • Lebenslanger Zugriff auf diesen Kurs
    • Alle künftigen Updates dieses Kurses
    • Downloads, Code und ein Zertifikat
    JS Unit Testing kaufen
  • All Access auf Academind Infinite

    25 $im Monat

    oder 249 $ 249 $ im JahrSpare 17 %

    • Jeder Kurs, mit allen Funktionen
    • Neue Kurse, sobald sie kommen
    • Dein Tutor, mit allen Funktionen
    All Access holen

All Access enthält außerdem jeden Academind Pro-Kurs.

Academind Pro und Academind Infinite

Zwei getrennte Plattformen, jede mit eigenen Kursen und eigener Anmeldung.

Academind Pro

Unsere ursprüngliche Kursplattform auf pro.academind.com. Dein Pro-Abo und die Kurse, die du dort gekauft hast, bleiben auf Pro.

Bei Academind Pro anmelden

Academind Infinite

Unsere neue KI-first-Plattform. Pro-Mitglieder melden sich mit ihrem Pro-Konto an, und Pro All Access enthält Infinite: Jeder Kurs ist offen.

Bei Academind Infinite anmelden

Hattest du ein Pro-Konto oder einen Kurs auf Pro gekauft?

Nicht jeder Pro-Kurs ist zu Infinite umgezogen, nur diese. Wähle deinen, um ihn auf Infinite zu sehen.