TypeScript testing with Vitest/Jest: file structure, mocking strategy, async patterns, and coverage targets
54
60%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./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.