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-4/

{
  "context": "The agent must extend an existing partial test suite for a payment processing service. The service has an internal validation method that should be observed with jest.spyOn rather than mocked entirely, and the tests must demonstrate proper spy lifecycle management and test isolation.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "jest.spyOn for internal method",
      "description": "Agent uses jest.spyOn() to observe or control the internal validate method on the service instance rather than replacing the whole module with jest.mock().",
      "max_score": 12
    },
    {
      "name": "spy restoration",
      "description": "Agent calls spy.mockRestore() after each test or uses jest.restoreAllMocks() in beforeEach to restore the original implementation.",
      "max_score": 12
    },
    {
      "name": "clearAllMocks in beforeEach",
      "description": "Agent calls jest.clearAllMocks() inside beforeEach (not afterEach) to reset call history between tests.",
      "max_score": 10
    },
    {
      "name": "jest.mock for external dependencies",
      "description": "Agent uses jest.mock() at module level for truly external dependencies (e.g., the payment gateway client), not jest.spyOn.",
      "max_score": 10
    },
    {
      "name": "MockedFunction casting",
      "description": "Agent casts mocked external dependency functions using 'as jest.MockedFunction<typeof fn>' for type safety.",
      "max_score": 8
    },
    {
      "name": "mockReturnValueOnce or mockResolvedValueOnce",
      "description": "Agent uses the *Once variants for per-test mock setup rather than persistent mockReturnValue or mockResolvedValue.",
      "max_score": 8
    },
    {
      "name": "toHaveBeenCalledWith on spy",
      "description": "Agent uses toHaveBeenCalledWith to verify the spy was called with the expected arguments.",
      "max_score": 8
    },
    {
      "name": "toHaveBeenCalledTimes on spy",
      "description": "Agent uses toHaveBeenCalledTimes to verify the exact invocation count on the spy.",
      "max_score": 8
    },
    {
      "name": "not mocking subject under test",
      "description": "Agent does not mock the PaymentService class itself — spying on its method is acceptable, but the service instance is real.",
      "max_score": 8
    },
    {
      "name": "async/await pattern",
      "description": "Agent uses async/await in all async test bodies rather than .then() chaining.",
      "max_score": 6
    },
    {
      "name": "describe/it structure",
      "description": "Added tests follow the existing describe/it structure — one top-level describe per class and nested describes per method.",
      "max_score": 5
    },
    {
      "name": "no .only calls",
      "description": "No test.only, it.only, or describe.only appears in the submitted file.",
      "max_score": 5
    }
  ]
}

evals

tile.json