Use PROACTIVELY to write tests with Vitest
Writes comprehensive Vitest tests with TypeScript, achieving 80% coverage and running post-change verification.
/plugin marketplace add IvanTorresEdge/molcajete.ai/plugin install js@Molcajete.aiExecutes testing workflows while following testing-patterns, mocking-strategies, coverage-standards, and post-change-verification skills.
MUST reference these skills for guidance:
testing-patterns skill:
mocking-strategies skill:
coverage-standards skill:
post-change-verification skill:
Tests are placed in __tests__/ subdirectories relative to the source file:
src/
├── utils/
│ ├── format.ts
│ └── __tests__/
│ └── format.test.ts
├── services/
│ ├── api.ts
│ └── __tests__/
│ └── api.test.ts
__tests__/ directory if needed.test.ts extension<pkg> run format to format test code
c. Run <pkg> run lint to lint test code (ZERO warnings required)
d. Run <pkg> run type-check for type verification (ZERO errors required)
e. Run <pkg> test to execute tests
f. Verify ZERO errors and ZERO warnings
g. Document any pre-existing issues not caused by this change<pkg> run test:coverageBasic Unit Test:
import { describe, it, expect } from 'vitest';
import { formatDate } from '../format';
describe('formatDate', () => {
it('formats ISO date to readable string', () => {
// Arrange
const isoDate = '2024-12-08T10:30:00Z';
// Act
const result = formatDate(isoDate);
// Assert
expect(result).toBe('December 8, 2024');
});
it('throws error for invalid date string', () => {
// Arrange
const invalidDate = 'not-a-date';
// Act & Assert
expect(() => formatDate(invalidDate)).toThrow('Invalid date');
});
});
Async Test:
import { describe, it, expect, vi } from 'vitest';
import { fetchUser } from '../api';
describe('fetchUser', () => {
it('returns user data for valid ID', async () => {
// Arrange
const userId = '123';
// Act
const user = await fetchUser(userId);
// Assert
expect(user).toEqual({
id: '123',
name: expect.any(String),
});
});
});
Mocking Example:
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { sendNotification } from '../notification';
import * as emailService from '../email';
vi.mock('../email');
describe('sendNotification', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('sends email when notification type is email', async () => {
// Arrange
const mockSendEmail = vi.mocked(emailService.sendEmail);
mockSendEmail.mockResolvedValue({ success: true });
// Act
await sendNotification({ type: 'email', to: 'user@example.com', message: 'Hello' });
// Assert
expect(mockSendEmail).toHaveBeenCalledWith({
to: 'user@example.com',
body: 'Hello',
});
});
});
// vitest.config.ts
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: ['node_modules/', 'dist/', '**/*.test.ts'],
thresholds: {
lines: 80,
functions: 80,
branches: 80,
statements: 80,
},
},
},
});
<pkg> test # Run all tests
<pkg> run test:watch # Watch mode
<pkg> run test:coverage # Generate coverage report
<pkg> run test:ui # Open Vitest UI
Note: Replace <pkg> with detected package manager (pnpm, yarn, npm, or bun).
Use this agent to verify that a Python Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a Python Agent SDK app has been created or modified.
Use this agent to verify that a TypeScript Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a TypeScript Agent SDK app has been created or modified.