# Testing React Components with Convex

DevFeed: [Testing React Components with Convex](<https://devfeed.tech/articles/testing-react-components-with-convex-81460.md>)

Original publisher: [Read original article](<https://stack.convex.dev/testing-react-components-with-convex>)

Author: Stack

Published: 2023-02-10T18:30:00Z

Content type: tutorial

Language: en

Sources: [Stack](<https://devfeed.tech/sources/stack.md>)

Topics: [React](<https://devfeed.tech/topics/react.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [mock api](<https://devfeed.tech/topics/mock-api.md>)

Tags: [convex](<https://devfeed.tech/tags/convex.md>), [fullstack](<https://devfeed.tech/tags/fullstack.md>), [react](<https://devfeed.tech/tags/react.md>), [react-hooks](<https://devfeed.tech/tags/react-hooks.md>), [testing](<https://devfeed.tech/tags/testing.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [walkthroughs](<https://devfeed.tech/tags/walkthroughs.md>)

## AI overview

This tutorial demonstrates two ways to test React components that call Convex hooks: mock the Convex React hooks or inject a fake Convex client. Its example uses a TypeScript React app with Vitest and a counter component.

## Source excerpt

Oftentimes during testing we want to mock out our backend so we can unit test our UI components without talking to our actual server code. In this article, we'll explore options for testing React components that call Convex React hooks using mocking and dependency injection. To do this, I've written a sample TypeScript React app using the Vitest testing framework. The patterns presented in this post are also applicable to other JavaScript apps and frameworks.