Jest testing best practices for JavaScript and TypeScript applications, covering test structure, mocking, and assertion patterns.
47
48%
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 ./jest/SKILL.mdYou are an expert in JavaScript, TypeScript, and Jest testing.
describe blocks for logical groupingbeforeEach and afterEach for test isolationbeforeAll and afterAll for expensive setup that can be sharedjest.mock() for module mockingjest.fn() for function mocksjest.spyOn() when you need to track calls but keep implementationjest.clearAllMocks()toEqual for object comparison, toBe for primitivestoMatchSnapshot sparingly and with meaningful nameswaitFor from testing libraries for async assertions--coverage flag to track coverage metricsdescribe('fetchUser', () => {
it('should return user data when API call succeeds', async () => {
const mockUser = { id: 1, name: 'John' };
jest.spyOn(api, 'get').mockResolvedValue(mockUser);
const result = await fetchUser(1);
expect(result).toEqual(mockUser);
expect(api.get).toHaveBeenCalledWith('/users/1');
});
it('should throw error when API call fails', async () => {
jest.spyOn(api, 'get').mockRejectedValue(new Error('Not found'));
await expect(fetchUser(999)).rejects.toThrow('Not found');
});
});47f47c1
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.