# Testing During Development (https://www.librechat.ai/docs/development/testing)

## Local Unit Tests

Before submitting your updates, verify they pass all unit tests. Follow these steps to run tests locally:

- Copy your `.env.example` file in the `/api` folder and rename it to `.env`

  ```bash filename="create a /api/.env file"
  cp .env.example ./api/.env
  ```

- Add `NODE_ENV=CI` to your `/api/.env` file
- `npm run test:client`
- `npm run test:api`
- `npm run test:packages:api`
- `npm run test:packages:data-provider`
- `npm run test:packages:data-schemas`

### Running Tests Per-Workspace

Tests are run using Jest from their respective workspace directories. Target specific test files with patterns:

```bash
cd api && npx jest <pattern>
cd packages/api && npx jest <pattern>
cd packages/data-provider && npx jest <pattern>
cd packages/data-schemas && npx jest <pattern>
cd client && npx jest <pattern>
```

## Testing Philosophy

- Prefer real logic over mocks. Mock only what cannot be controlled locally, such as external HTTP
  APIs, rate-limited services, and non-deterministic system calls.
- Use spies when you need to assert that real functions were called with expected arguments.
- Use `mongodb-memory-server` for MongoDB-backed tests so queries and schema validation run against
  real database behavior.
- Cover loading, success, and error states for UI/data flows.

<Callout type="tip" title="Tip">
  Use `test/layout-test-utils` for rendering components in frontend tests.
</Callout>
