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

---
id: ac1f37c8-8dfd-4c0a-8d64-776f4265da6f
---

# Testing for CMS React

> Learn how to implement unit tests for a CMS React project.

React components are easy to unit test with [Vitest](https://vitest.dev/) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/).

To add tests to your own project, start by adding those packages as dev dependencies, as well as `@vitejs/plugin-react` for React support.

```jsx theme={null}
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:

```javascript theme={null}
// @vitest-environment jsdom
```

This enables React Testing Library’s [`render`](https://testing-library.com/docs/react-testing-library/api/#render) function to work. Learn more about [Vitest test environments](https://vitest.dev/guide/environment.html#test-environment)
