Skip to content
Back to skills

Vitest Testing

ASecurity

Write and run Vitest unit and integration tests. Use when creating tests, debugging test failures, or checking test coverage.

  • 57 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
testingtypescriptbashtestingdebuggingrefactoring

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill vitest-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vitest Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Vitest Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-vitest-testing-awesome-omni-skill/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-vitest-testing-awesome-omni-skill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: vitest-testing
description: Write and run Vitest unit and integration tests. Use when creating tests, debugging test failures, or checking test coverage.
metadata:
  version: '1.0'
---

# Vitest Testing

## Running Tests

```bash
# Run all tests
npx vitest run

# Run in watch mode
npx vitest

# Run with coverage
npx vitest run --coverage

# Run a specific test file
npx vitest run src/utils/stats.test.ts

# Run tests matching a pattern
npx vitest run -t "rolling average"
```

## Test File Naming

- Unit tests: `<module>.test.ts` co-located with the source file
- Integration tests: `<feature>.integration.test.ts` in a `__tests__/` directory

## Test Structure

```typescript
import { describe, it, expect, beforeEach, vi } from 'vitest';

describe('ModuleName', () => {
  describe('functionName', () => {
    it('should describe expected behavior', () => {
      // Arrange
      const input = createTestInput();

      // Act
      const result = functionName(input);

      // Assert
      expect(result).toEqual(expectedOutput);
    });

    it('should handle edge case', () => {
      expect(() => functionName(null)).toThrow('Expected valid input');
    });
  });
});
```

## Best Practices

- Test behavior, not implementation. If internal refactoring breaks tests, the tests are too coupled.
- Use descriptive test names: `should calculate rolling AHI average with gaps in data`
- Test edge cases: empty arrays, single elements, NaN values, boundary conditions.
- Mock external dependencies (IndexedDB, OPFS, Web Workers) using `vi.mock()`.
- Use `beforeEach` for setup, not shared mutable state.
- For statistical functions, compare against known values from reference implementations.
- Use `toBeCloseTo()` for floating-point comparisons.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.