Visão Geral
Este curso apresenta os fundamentos dos testes em aplicações React utilizando Jest e React Testing Library (RTL). Você aprenderá por que testar, como estruturar testes, como testar componentes, eventos, hooks e comportamentos essenciais. Tudo de forma simples, direta e prática, preparando você para escrever testes confiáveis em qualquer projeto React.
Conteúdo Programatico
Module 1 – Introduction to Testing
- Why testing matters
- Types of tests (unit, integration, E2E)
- How Jest and RTL work together
- Understanding testing philosophy
Module 2 – Setting Up the Environment
- Installing Jest and RTL
- Required configurations
- Test folder structure
- Running the first test
Module 3 – Jest Fundamentals
- Test blocks (describe, test, it)
- matchers (toBe, toEqual, toHaveBeenCalled…)
- Mocking functions and modules
- Snapshot testing basics
Module 4 – React Testing Library Essentials
- Rendering components
- getBy vs queryBy vs findBy
- Best practices for querying elements
- Understanding the screen object
Module 5 – Testing Interactions
- Click, change, typing and form events
- Simulating user behavior with userEvent
- Testing state changes
- Testing error and loading states
Module 6 – Testing Components
- Testing props
- Testing conditional rendering
- Testing async components
- Mocking APIs and fetch calls
Module 7 – Testing Custom Hooks
- Using renderHook
- Testing hook logic and return values
- Mocking dependencies
Module 8 – Best Practices & Common Patterns
- What to test and what not to test
- Avoiding implementation details
- Organizing tests by domain
- Minimizing brittle tests
Module 9 – Final Project
- Creating a small React application
- Writing tests for:
- Components
- Inputs/forms
- Hooks
- API calls
- Achieving consistent test coverage