TypeScript testing with Vitest/Jest: file structure, mocking strategy, async patterns, and coverage targets
54
60%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No known issues
Fix and improve this skill with Tessl
tessl review fix ./skills/testing-typescript/SKILL.mdvitest run / vitest run --coveragesrc/utils/format.ts → src/utils/format.test.tstests/fixtures/ or src/__tests__/helpers/describe('formatDate', () => {
it('should return ISO date string when given a valid Date', () => {
// Arrange
const date = new Date('2026-01-15');
// Act
const result = formatDate(date);
// Assert
expect(result).toBe('2026-01-15');
});
});// Module mock — top of file
vi.mock('../services/emailService');
// Spy without full mock
const spy = vi.spyOn(mailer, 'send').mockResolvedValue(undefined);
// Restore after each test
afterEach(() => vi.restoreAllMocks());
// Time control
beforeEach(() => vi.useFakeTimers());
afterEach(() => vi.useRealTimers());// Always await; use assertions count for safety
it('should reject with AuthError when token is expired', async () => {
expect.assertions(1);
await expect(verifyToken('expired')).rejects.toThrow('Token expired');
});c0b2e4b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.