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

criteria.jsonevals/scenario-2/

{
  "context": "The agent must write Jest tests for an Express REST API that handles product inventory. The service layer depends on a database repository that must be mocked. Tests include both success paths and error scenarios, requiring proper async assertion patterns.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "jest.mock at module level",
      "description": "Agent uses jest.mock() at module level to mock the repository or database dependency, not manual injection or monkey-patching.",
      "max_score": 10
    },
    {
      "name": "MockedFunction casting",
      "description": "Agent casts mocked functions using 'as jest.MockedFunction<typeof fn>' for type-safe mock access in TypeScript.",
      "max_score": 8
    },
    {
      "name": "clearAllMocks in beforeEach",
      "description": "Agent calls jest.clearAllMocks() in beforeEach (not afterEach) to ensure mock isolation between tests.",
      "max_score": 10
    },
    {
      "name": "mockResolvedValueOnce usage",
      "description": "Agent uses mockResolvedValueOnce for per-test async return values rather than persistent mockResolvedValue.",
      "max_score": 10
    },
    {
      "name": "expect.assertions usage",
      "description": "Agent uses expect.assertions(n) in at least one test where assertions could be silently skipped (e.g., error path tests or callback-based assertions).",
      "max_score": 10
    },
    {
      "name": "rejects.toThrow or error response check",
      "description": "Agent tests error paths by asserting on the HTTP error status code and/or using await expect(...).rejects.toThrow() patterns for rejected promises.",
      "max_score": 8
    },
    {
      "name": "toHaveBeenCalledWith verification",
      "description": "Agent verifies that the mocked repository is called with the correct arguments.",
      "max_score": 8
    },
    {
      "name": "toHaveBeenCalledTimes verification",
      "description": "Agent verifies the number of times critical repository methods are called (alongside toHaveBeenCalledWith).",
      "max_score": 8
    },
    {
      "name": "async/await pattern",
      "description": "Agent uses async/await in all async test functions rather than .then() chaining or done callbacks.",
      "max_score": 8
    },
    {
      "name": "describe/it structure",
      "description": "Agent uses one top-level describe per route or controller with nested describe blocks per HTTP method or endpoint.",
      "max_score": 8
    },
    {
      "name": "it() verb-first descriptions",
      "description": "All it() descriptions start with a verb ('returns', 'responds', 'creates', 'rejects') not 'should ...'.",
      "max_score": 7
    },
    {
      "name": "no .only calls",
      "description": "No test.only, it.only, or describe.only appears in the submitted test file.",
      "max_score": 5
    }
  ]
}

evals

tile.json