> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Write Unit Tests for a Wix CLI App ## Article: Write Unit Tests for a Wix CLI App ## Article Link: https://dev.wix.com/docs/wix-cli/legacy-clis/legacy-wix-cli-for-apps/app-development/write-unit-tests-for-a-wix-cli-app.md ## Article Content: # Write Unit Tests for a Wix CLI Application
**Deprecated** The Wix CLI for Apps is deprecated and no longer receives updates or new features. New projects should use the unified [Wix CLI](https://dev.wix.com/docs/wix-cli/guides/about-the-wix-cli.md). [Determine which CLI your project uses](https://dev.wix.com/docs/wix-cli/guides/development/determine-which-cli-your-project-uses.md).This article explains how to write unit tests for a CLI application using [Vitest](https://vitest.dev/) and `@testing-library/react`. > **Note:** While this article's flow uses Vitest specifically, the CLI is framework-agnostic and supports any testing library. This article covers: - Preparing your app for unit testing with Vitest. - Writing unit tests for your app. ## Before you begin Before getting started, make sure that: - You have an app project that was [created using the Wix CLI](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/wix-cli/get-started/quick-start.md). - You're logged into your Wix Studio account. If you don't already have one, [sign up for a Wix Studio account](https://manage.wix.com/account/custom-apps). ## Step 1 | Prepare your app for unit testing with Vitest 1. Run the following command to install the required packages: ```bash npm add vitest jsdom @testing-library/jest-dom @testing-library/user-event @testing-library/react@12 -D ``` > **Note**: Since the Wix CLI uses React 16, we currently only support version 12 of `@testing-library/react`. 2. Create or update your `vitest.config.js` file with the following configuration: ```javascript import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { include: ['src/**/*.(test|spec).ts?(x)'], exclude: ['build', 'node_modules'], environment: 'jsdom', maxConcurrency: 7, setupFiles: './tests/setup.ts', }, }); ``` 3. Create a test setup file at `tests/setup.ts`. This file is used for general test configuration with Vitest: ```javascript import { expect, afterEach } from 'vitest'; import { cleanup } from '@testing-library/react'; import * as matchers from '@testing-library/jest-dom/matchers'; expect.extend(matchers); afterEach(() => { cleanup(); }); ``` 4. Add the following script to your `package.json` file to trigger unit tests: ```json { "name": "your-wix-cli-app", "version": "1.0.0", "private": true, "scripts": { "wix": "wix", "test:unit": "vitest run" // ... }, } ``` ## Step 2 | Write unit tests for your app Depending on your app's functionality, testing your app's react components may involve mocking Wix Javascript SDK APIs, backend interactions, or both. ### Testing a react component without the SDK or backend interactions To test a react component like a dashboard page, check that aspects of the component would be rendered correctly. For example, given the following dashboard page: ```javascript import React, { type FC } from 'react'; import { EmptyState, Page } from '@wix/design-system'; import '@wix/design-system/styles.global.css'; const Index: FC = () => { return (