Saltar al contenido
Skillpedia
Pruebas48 mil · #6125

vitest-skill

Qué hace

Esta herramienta te ayuda a escribir tests automáticos para tu código JavaScript o TypeScript. Usa Vitest, que es rápido y compatible con herramientas como Jest.

Cuándo usarla

  • ✓Cuando necesitas escribir tests para tu código.
  • ✓Cuando usas Vitest, vi.mock o vitest.config.
  • ✓Para probar componentes de React o simular funciones.

Link de la skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vitest-skill/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vitest-skill/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Escribe un test para la función `add` que compruebe si 2 + 2 es igual a 4.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La herramienta genera código de tests con la sintaxis de Vitest. Puede crear tests básicos, simular partes de tu código (mocking) o incluso probar componentes.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

Vitest Testing Skill

When to Use

Use this skill when you need generates Vitest tests in JavaScript/TypeScript with Vite-native speed. Jest-compatible API with ESM support and HMR. Use when user mentions "Vitest", "vi.mock", "vitest.config". Triggers on: "Vitest", "vi.mock", "vi.fn", "Vite test", "vitest config".

Core Patterns

Basic Test

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Calculator } from './calculator';

describe('Calculator', () => {
  let calc: Calculator;
  beforeEach(() => { calc = new Calculator(); });

  it('adds two numbers', () => {
    expect(calc.add(2, 3)).toBe(5);
  });

  it('throws on divide by zero', () => {
    expect(() => calc.divide(10, 0)).toThrow();
  });
});

Mocking (vi instead of jest)

import { vi } from 'vitest';

// Mock module
vi.mock('./database', () => ({
  getUser: vi.fn().mockResolvedValue({ name: 'Alice' }),
  saveUser: vi.fn().mockResolvedValue(true),
}));

// Mock function
const mockFn = vi.fn();
mockFn.mockReturnValue(42);
mockFn.mockResolvedValue({ data: 'test' });

// Spy
const spy = vi.spyOn(console, 'log').mockImplementation(() => {});
expect(spy).toHaveBeenCalledWith('message');
spy.mockRestore();

// Timers
vi.useFakeTimers();
vi.advanceTimersByTime(1000);
vi.runAllTimers();
vi.useRealTimers();

In-Source Testing

// src/math.ts — tests alongside code!
export function add(a: number, b: number) { return a + b; }
export function multiply(a: number, b: number) { return a * b; }

if (import.meta.vitest) {
  const { it, expect } = import.meta.vitest;
  it('adds', () => { expect(add(2, 3)).toBe(5); });
  it('multiplies', () => { expect(multiply(3, 4)).toBe(12); });
}

Snapshot Testing

it('serializes user', () => {
  expect(serializeUser(user)).toMatchSnapshot();
});

it('inline snapshot', () => {
  expect(serializeUser(user)).toMatchInlineSnapshot(`
    { "name": "Alice", "email": "alice@test.com" }
  `);
});

React Component Testing

import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import Button from './Button';

describe('Button', () => {
  it('renders with label', () => {
    render(<Button label="Click me" />);
    expect(screen.getByText('Click me')).toBeDefined();
  });
});

Anti-Patterns

Bad Good Why
jest.fn() vi.fn() Vitest uses vi
jest.mock() vi.mock() Different namespace
No type safety TypeScript + strict Vitest is TS-first

Quick Reference

Task Command
Run once npx vitest run
Watch npx vitest (default)
UI npx vitest --ui
Coverage npx vitest --coverage
Specific file npx vitest run src/math.test.ts
Filter npx vitest run -t "adds"

vitest.config.ts

import { defineConfig } from 'vitest/config';
export default defineConfig({
  test: {
    globals: true,
    environment: 'jsdom',
    coverage: { provider: 'v8', reporter: ['text', 'html'] },
    include: ['src/**/*.{test,spec}.{js,ts,tsx}'],
    includeSource: ['src/**/*.{js,ts}'],
  },
});

Deep Patterns → reference/playbook.md

§ Section Lines
1 Production Configuration Config, workspace, setup file
2 Mocking Patterns vi.mock, spies, timers, fetch
3 React Testing Library Components, hooks, providers
4 Snapshot & Inline Snapshots File, inline, serializers
5 Table-Driven Tests test.each, describe.each
6 In-Source Testing Co-located tests in source
7 API / Integration Testing Server tests with fetch
8 CI/CD Integration GitHub Actions, scripts
9 Debugging Quick-Reference 10 common problems
10 Best Practices Checklist 13 items

Limitations

  • Use this skill only when the task clearly matches its upstream source and local project context.
  • Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
  • Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
Preguntas frecuentes

¿Cuál es la diferencia entre Vitest y Jest?

Vitest es más rápido y usa funciones modernas de JavaScript, y es compatible con la mayoría de las funciones de Jest.

¿Qué es el 'mocking'?

Es crear versiones falsas de algunas partes de tu código para probar otras partes de forma aislada.

¿Qué es el 'snapshot testing'?

Es una forma de probar lo que devuelve tu código comparándolo con una 'instantánea' anterior (una grabación del resultado).

Detalles

Descripción original del autor

Generates Vitest tests in JavaScript/TypeScript with Vite-native speed. Jest-compatible API with ESM support and HMR. Use when user mentions "Vitest", "vi.mock", "vitest.config". Triggers on: "Vitest", "vi.mock", "vi.fn", "Vite test", "vitest config".

repo: sickn33/agentic-awesome-skills

Popularidad

Estrellas en GitHub
48 mil
Posición en el ranking
#6125
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas