Cursor Rules for
Vitest Testing

This rule explains the guidelines for writing Vitest tests for Next.js applications.
Back to rules
Type
Integration
Language(s)
JavaScript
TypeScript
Stats
108 views
11 copies
4 downloads
Author
Elie Steinbock
Elie Steinbock
vitest-testing.mdc
---
description: This rule explains the guidelines for writing Vitest tests for Next.js applications.
globs: *
alwaysApply: false
---

# Testing Guidelines

## Testing Framework
- `vitest` is used for testing
- Tests are colocated next to the tested file
  - Example: `dir/format.ts` and `dir/format.test.ts`

## Common Mocks

### Server-Only Mock
```ts
vi.mock("server-only", () => ({}));
```

### Prisma Mock
```ts
import { beforeEach } from "vitest";
import prisma from "@/utils/__mocks__/prisma";

vi.mock("@/utils/prisma");

describe("example", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("test", async () => {
    prisma.group.findMany.mockResolvedValue([]);
  });
});
```

## Best Practices
- Each test should be independent
- Use descriptive test names
- Mock external dependencies
- Clean up mocks between tests
- Avoid testing implementation details
Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later