Pular para o conteúdo principal
Academind
Todos os cursos

Curso do 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 seções · 92 aulas
  • 5 h e 38 min no total
JavaScript Unit Testing - The Practical Guide

Sobre este curso

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.

O que você vai aprender

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é-requisitos

  • Basic JavaScript knowledge is required.

  • No prior testing knowledge is necessary.

Para quem é este curso

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

Conteúdo do curso

Confira a estrutura e o ritmo deste curso antes de começar.

  1. 1Getting Started8 aulas · 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 aulas · 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 aulas · 1 h e 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 aulas · 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 aulas · 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 aulas · 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 aulas · 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 aulas · 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 aulas · 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 aulas · 4 min
    1. 01Course Roundup4:10 min
    2. 02Bonus: More Courses & Content0:00 min

Pronto para começar?

Compre este curso no Academind Pro ou tenha todos os cursos com o All Access no Academind Infinite.

Black Friday: um ano de All Access por US$ 249 US$ 249 · só até Aproveite a oferta
  • Este curso no Academind Pro

    US$ 69pagamento único

    Impostos incluídos · Garantia de reembolso de 30 dias

    • Acesso vitalício a este curso
    • Todas as futuras atualizações deste curso
    • Materiais para download, código e um certificado
    Comprar JS Unit Testing
  • All Access no Academind Infinite

    US$ 25por mês

    ou US$ 249 US$ 249 por anoEconomize 17%

    • Todos os cursos, com todos os recursos
    • Cursos novos assim que saem
    • Seu tutor, com todos os recursos
    Assinar o All Access

O All Access também inclui todos os cursos do Academind Pro.

Academind Pro e Academind Infinite

Duas plataformas separadas, cada uma com seus próprios cursos e seu próprio login.

Academind Pro

Nossa plataforma de cursos original, em pro.academind.com. Sua assinatura do Pro e os cursos que você comprou lá continuam no Pro.

Entrar no Academind Pro

Academind Infinite

Nossa nova plataforma pensada para IA. Membros do Pro entram com a conta do Pro, e o Pro All Access inclui o Infinite: todos os cursos ficam liberados.

Entrar no Academind Infinite

Tinha uma conta no Pro ou comprou um curso no Pro?

Nem todo curso do Pro foi para o Infinite, só estes. Escolha o seu para vê-lo no Infinite.