Last modified: November 18, 2025
React components are easy to unit test with Vitest and React Testing Library.
To add tests to your own project, start by adding those packages as dev dependencies, as well as @vitejs/plugin-react for React support.
vitest.config.js file in your package root.
When writing a test file that uses React Testing Library to render components or reference any browser-specific APIs, add the following to the top of the file:
render function to work. Learn more about Vitest test environments