
Vitest
Configure Vitest and write unit, type, and mock tests for TypeScript, React, and Vue projects without hunting scattered docs.
Overview
Vitest is an agent skill for the Ship phase that supplies Vitest configuration and testing patterns for Node, React, and Vue TypeScript codebases.
Install
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill vitestWhat is this skill?
- Ready-made vitest.config.ts variants for node, React (jsdom + setupFiles), and Vue (happy-dom)
- Patterns for describe/it structure, expectTypeOf/assertType type tests, and vi.mock / vi.mocked spies
- Coverage provider v8 and globals enabled in reference configs
- Framework plugin wiring via @vitejs/plugin-react and @vitejs/plugin-vue
- 3 framework config examples (node, React, Vue)
- 7+ indexed testing pattern sections in the skill index
Adoption & trust: 576 installs on skills.sh; 53 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You adopted Vite and Vitest but your agent keeps suggesting wrong environments, missing setup files, or Jest-style mocks that do not match your stack.
Who is it for?
Solo builders on Vite + TypeScript who want fast unit, component, and type tests with consistent config snippets from the agent.
Skip if: Teams standardized on Jest-only workflows with no Vite, or E2E-only strategies where Playwright/Cypress skills are the right fit instead.
When should I use this skill?
You are adding or refactoring Vitest config, DOM environments, mocks, or type tests in a Vite TypeScript project.
What do I get? / Deliverables
After using the skill, your agent outputs aligned vitest.config.ts files, DOM test setup, and vi.mock examples you can paste into suites and CI.
- vitest.config.ts snippets
- describe/it and mock code blocks
- React/Vue test environment setup
Recommended Skills
Journey fit
Automated test setup and patterns belong on the Ship shelf because they gate safe releases after build work is done. Testing is the canonical subphase for runner config, coverage, jsdom/happy-dom environments, and vi.mock patterns.
How it compares
Use for Vite-native unit and component tests with vi APIs—not as a replacement for browser E2E or full CI pipeline skills.
Common Questions / FAQ
Who is vitest for?
Vitest is for solo and indie developers using Vitest on Node, React, or Vue projects who want their agent to generate correct configs, mocks, and type-test patterns.
When should I use vitest?
Use it during Ship when you are setting up coverage, choosing jsdom or happy-dom, writing vi.mock spies, or adding TypeScript expectTypeOf checks before you merge or deploy.
Is vitest safe to install?
Review the Security Audits panel on this Prism page and the skill source in your repo before granting agent filesystem or shell access to run tests locally.
SKILL.md
READMESKILL.md - Vitest
# Vitest Skill - Code Examples Index Quick reference for all code examples included in the Vitest skill. --- ## Configuration Examples ### 1. Basic Vitest Config ```typescript // vitest.config.ts import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, environment: 'node', coverage: { provider: 'v8' }, }, }); ``` ### 2. React Config ```typescript // vitest.config.ts with React import { defineConfig } from 'vitest/config'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], test: { globals: true, environment: 'jsdom', setupFiles: './src/test/setup.ts', }, }); ``` ### 3. Vue Config ```typescript // vitest.config.ts with Vue import { defineConfig } from 'vitest/config'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [vue()], test: { globals: true, environment: 'happy-dom', }, }); ``` --- ## Testing Patterns ### 4. Basic Test Structure ```typescript describe('Calculator', () => { it('adds two numbers', () => { expect(2 + 3).toBe(5); }); }); ``` ### 5. TypeScript Type Testing ```typescript import { expectTypeOf, assertType } from 'vitest'; it('checks types', () => { expectTypeOf(user.id).toBeNumber(); assertType<User>(user); }); ``` ### 6. Module Mocking ```typescript vi.mock('./api', () => ({ fetchUser: vi.fn(), })); vi.mocked(fetchUser).mockResolvedValue({ id: 1 }); ``` ### 7. Method Spying ```typescript const spy = vi.spyOn(logger, 'log'); logger.log('Hello'); expect(spy).toHaveBeenCalledWith('Hello'); ``` ### 8. Timer Mocking ```typescript vi.useFakeTimers(); vi.advanceTimersByTime(1000); await vi.runAllTimersAsync(); ``` --- ## React Testing ### 9. Component Testing ```typescript import { render, screen } from '@testing-library/react'; it('renders component', () => { render(<Counter initialCount={0} />); expect(screen.getByText('Count: 0')).toBeInTheDocument(); }); ``` ### 10. User Interaction ```typescript import userEvent from '@testing-library/user-event'; const user = userEvent.setup(); await user.click(screen.getByRole('button')); ``` ### 11. Hook Testing ```typescript import { renderHook, act } from '@testing-library/react'; const { result } = renderHook(() => useCounter(0)); act(() => result.current.increment()); expect(result.current.count).toBe(1); ``` --- ## Vue Testing ### 12. Vue Component Testing ```typescript import { mount } from '@vue/test-utils'; const wrapper = mount(Counter, { props: { initialCount: 5 }, }); expect(wrapper.text()).toContain('Count: 5'); ``` ### 13. Event Emission ```typescript await wrapper.find('button').trigger('click'); expect(wrapper.emitted('update')).toBeTruthy(); expect(wrapper.emitted('update')?.[0]).toEqual([1]); ``` --- ## Async Testing ### 14. Promise Testing ```typescript await expect(Promise.resolve(42)).resolves.toBe(42); await expect(Promise.reject(new Error('fail'))).rejects.toThrow('fail'); ``` ### 15. Fetch Mocking ```typescript global.fetch = vi.fn(() => Promise.resolve({ json: () => Promise.resolve('data'), } as Response) ); const data = await fetchData(1); expect(data).toBe('data'); ``` --- ## Snapshot Testing ### 16. Basic Snapshot ```typescript expect(container.firstChild).toMatchSnapshot(); ``` ### 17. Inline Snapshot ```typescript expect(user).toMatchInlineSnapshot(` { "id": 1, "name": "Bob", } `); ``` --- ## Advanced Patterns ### 18. Concurrent Testing ```typescript describe.concurrent('Parallel Tests', () => { it('test 1', async () => { await slowOperation(); }); it('test 2', async () => { await slowOperation(); }); }); ``` ### 19. Custom Matchers ```typescript expect.extend({ toBeWithinRange(received, floor, ceiling) { const pass = received >= floor && received <= ceiling; return { pass, message: () => '...' }; }, }); expect(100).toBeWithinRange(90, 110); ``` ### 20. Test Context ```typescript d