Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
React Testing Library with Jest / Vitest
Rating: 4.6 out of 5(7,881 ratings)
42,649 students

React Testing Library with Jest / Vitest

Learn best practices for testing your apps with Jest / Vitest and React Testing Library. All code written via TDD!
Created byBonnie Schulkin
Last updated 3/2026
English

What you'll learn

  • Testing simple and complex React applications with React Testing Library
  • React Testing best Practices: how to test behavior instead of implementation
  • Making the most of Jest watch mode, including running only one file or test at a time
  • Common errors returned by Testing Library and how to correct them
  • Test-Driven Development: writing tests alongside production code, to ensure thorough test coverage

Course content

9 sections87 lectures7h 18m total length
  • Introduction to React Testing Library and Jest / Vitest4:26

    Explore the philosophy of React Testing Library, focusing on testing like users, using accessibility markers, and avoiding test IDs, while comparing Jest and Vitest as test runners.

  • Link to course GitHub repo0:03
  • First Test with Testing Library8:09

    Set up a React testing environment with Veit, Babel, and Webpack, clone the course repo, and install dependencies. Render the app and verify headings with React Testing Library's getByText.

  • Jest and Jest-DOM Assertions4:09

    Master assertions in jest or vitest by using expect with dom matchers to determine test outcomes, see examples like text content and length checks, and import jest-dom in setup file.

  • Jest and Vitest: How Tests Work6:03

    Explore how jest and vitest work with react testing library to run tests quickly, understand test runners, assertions, and how tests pass or fail.

  • TDD: Test Driven Development3:28

    Learn test driven development (TDD) by writing tests before code, observe red tests, then implement code to make them green, and experience integrated, efficient regression testing.

  • React Testing Library Philosophy4:29

    Discover how the React Testing Library philosophy promotes best practices by testing user behavior in a virtual dom, with unit, integration, functional, and end-to-end tests.

  • Functional Testing vs Unit Testing4:20

    Functional testing includes all relevant units for a user flow, mirroring how users interact with your software, while unit tests isolate dependencies to test internals.

  • TDD (Test Driven Development) vs BDD (Behavior Driven Development)1:27

    Clarify the difference between test driven development and behavior driven development, noting that this course uses test driven development and tests behavior with the testing library, without adopting behavior driven development.

  • Testing Library and Accessibility5:23

    Discover how testing library guides element selection using accessibility roles and name-based queries, prioritizing getByRole for screen reader friendly tests. Use getByRole, getByLabelText, and queries to build accessible tests.

  • RESOURCE: Where to find code if you'd rather not write React for this course1:40

Requirements

  • Experience with JavaScript
  • Basic experience with React
  • Familiarity with React hooks and context (these are explained briefly in optional React portions of the course; however previous experience would be helpful)

Description

Major course updates in November 2023! 

  • Projects are written in Vite, a lightweight and lightning-fast base for React apps

  • Projects use Vitest, a test framework that's much faster than Jest
    Note: Vitest code syntax is identical to Jest; all code presented in the course works with both Vitest and Jest.

  • The course presents Mock Service Worker v2 syntax, which was released in October 2023.


React Testing Library has become an extremely popular option for testing React, and with good reason! This detailed, comprehensive course provides a solid foundation for React app tests.


Best Practices

React Testing Library is famously opinionated about testing best practices, and is written to encourage these best practices. This course teaches:

  • testing behavior over testing implementation

  • tests that interact with your app the way a user would

  • finding elements by accessibility handles, to make sure your code is accessible as possible

Broad range of testing examples

The course apps start very with very simple examples (clicking a button to change its color) and work up to progressively more complicated testing concepts, such as: 

  • testing asynchronous page changes

  • simulating data from a server using Mock Service Worker

  • applying a context provider to a component when rendering

The course builds up to complex concepts gradually, in a way designed to support your learning and ensure your success.

Practice your new skills

You will also have plenty of opportunities to practice what you’ve learned. The course provides "code quizzes" while building the course projects, where you can apply what you learned and then watch a video to see the solution. The (optional) final section provides even more exercises to complete the second app and reinforce concepts from the course.

Optional React lectures

Any significant React code covered in the course is isolated into separate lectures. Students have a choice: those who want to reinforce their React skills (or learn new ones!) can watch those lectures, while students who feel confident in their React skills can skip them.

Supportive Instructor

The instructor has a proven track record of responding to course Q&A in a helpful and supportive way. She loves to engage with students, answer questions about course concepts, and help debug students' code for the course projects.

Who this course is for:

  • React coders who want to learn how to write functional tests for their apps
  • React application engineers who want confidence that writing code doesn't break existing behavior (tests, for the win!)