Awesome-omni-skill vitest-testing
Write and run Vitest unit and integration tests. Use when creating tests, debugging test failures, or checking test coverage.
install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/testing-security/vitest-testing" ~/.claude/skills/diegosouzapw-awesome-omni-skill-vitest-testing-8fc1a4 && rm -rf "$T"
manifest:
skills/testing-security/vitest-testing/SKILL.mdsource content
Vitest Testing
Running Tests
# 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:
co-located with the source file<module>.test.ts - Integration tests:
in a<feature>.integration.test.ts
directory__tests__/
Test Structure
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
for setup, not shared mutable state.beforeEach - For statistical functions, compare against known values from reference implementations.
- Use
for floating-point comparisons.toBeCloseTo()