# Unit Testing with Vitest in MakerKit

> Run and write unit tests with the Vitest setup used by the current monorepo.

*Canonical: https://makerkit.dev/docs/nextjs-drizzle/testing/unit*

---

Unit tests live across packages and run through Vitest.

## Run Tests

All unit tests:

```bash
pnpm test:unit
```

Single package:

```bash
pnpm --filter @kit/rbac test:unit
pnpm --filter @kit/database test:unit
```

Watch mode is only available in packages that define `test:unit:watch`:

```bash
pnpm --filter @kit/rbac test:unit:watch
```

## Coverage

There is no repo-wide `test:unit:coverage` convention. If you need coverage for a package, run Vitest directly for that package.

## Where Tests Live

Tests usually sit near the code they cover, for example:

```text
packages/rbac/src/core/__tests__/
packages/database/src/services/
packages/organization/core/src/services/__tests__/
```

## Good Candidates

- pure functions
- service logic
- schema validation
- RBAC and policy behavior
- database helpers and test utilities
