CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/jest-testing

Jest testing patterns — test structure, mocking, async testing, snapshot

99

1.26x
Quality

99%

Does it follow best practices?

Impact

99%

1.26x

Average score across 6 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

Evaluation results

96%

47%

Write Tests for the Notification Service

async service mocking

Criteria
Without context
With context

jest.mock at module level

0%

83%

MockedFunction casting

37%

75%

clearAllMocks in beforeEach

0%

100%

mockResolvedValueOnce usage

0%

100%

toHaveBeenCalledWith verification

100%

100%

toHaveBeenCalledTimes verification

25%

100%

async/await pattern

100%

100%

rejects.toThrow for errors

100%

100%

describe/it structure

100%

100%

it() verb-first descriptions

0%

100%

no .only calls

100%

100%

not mocking subject under test

100%

100%

99%

29%

Write Tests for the Inventory API

API route testing with mocks

Criteria
Without context
With context

jest.mock at module level

100%

100%

MockedFunction casting

62%

87%

clearAllMocks in beforeEach

100%

100%

mockResolvedValueOnce usage

0%

100%

expect.assertions usage

0%

100%

rejects.toThrow or error response check

87%

100%

toHaveBeenCalledWith verification

100%

100%

toHaveBeenCalledTimes verification

37%

100%

async/await pattern

100%

100%

describe/it structure

87%

100%

it() verb-first descriptions

100%

100%

no .only calls

100%

100%

100%

5%

Set Up Jest Testing for a New TypeScript Service

Jest TypeScript configuration

Criteria
Without context
With context

ts-jest preset

100%

100%

node testEnvironment

100%

100%

roots points to src

100%

100%

testMatch for .test.ts files

100%

100%

collectCoverageFrom set correctly

100%

100%

test script in package.json

100%

100%

test:watch script in package.json

100%

100%

test:coverage script in package.json

100%

100%

jest.config.ts uses export default

100%

100%

setupFilesAfterFramework referenced

37%

100%

ts-jest and jest devDependencies

100%

100%

jest.setup.ts file created

100%

100%

100%

12%

Extend the Payment Service Test Suite

spyOn and test isolation

Criteria
Without context
With context

jest.spyOn for internal method

100%

100%

spy restoration

0%

100%

clearAllMocks in beforeEach

100%

100%

jest.mock for external dependencies

100%

100%

MockedFunction casting

100%

100%

mockReturnValueOnce or mockResolvedValueOnce

100%

100%

toHaveBeenCalledWith on spy

100%

100%

toHaveBeenCalledTimes on spy

100%

100%

not mocking subject under test

100%

100%

async/await pattern

100%

100%

describe/it structure

100%

100%

no .only calls

100%

100%

100%

10%

Write Tests for the Request Rate Limiter

Criteria
Without context
With context

useFakeTimers in beforeEach

100%

100%

useRealTimers in afterEach

100%

100%

advanceTimersByTime usage

100%

100%

clearAllMocks in beforeEach

0%

100%

toHaveBeenCalledTimes verification

100%

100%

boundary condition tests

100%

100%

describe/it structure

100%

100%

it() verb-first descriptions

100%

100%

no .only calls

100%

100%

not mocking subject under test

100%

100%

Evaluated
Agent
Claude Code
Model
Claude Sonnet 4.6

Table of Contents