Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developers.hubspot.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

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.
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
});
For Vitest to work properly with your React components, you’ll also need to add a 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:
// @vitest-environment jsdom
This enables React Testing Library’s render function to work. Learn more about Vitest test environments
Last modified on January 28, 2026