AI Toolkit
Modulestesting

testing

Mock AI, MCP, DB, workflows — zero API calls in tests

Overview

The testing module provides mock implementations for every toolkit module. Use them to write fast, deterministic tests with zero external API calls.

No peer dependencies required.

Quick Start

import { mockAI, mockDatabase, mockMonitor } from '@jamaalbuilds/ai-toolkit/testing';

const ai = mockAI({ text: 'Hello world' });
const db = mockDatabase();
const monitor = mockMonitor();

API Reference

mockAI(options?)

Mock the AI client.

function mockAI(options?: MockAIOptions): AIClient
const ai = mockAI({ text: 'Test response' });
const result = await ai.generate('any prompt');
expect(result.text).toBe('Test response');
expect(ai._tracker.callCount).toBe(1);

mockChain(options?)

Mock the chain module.

mockAgents(options?)

Mock the agents module.

mockKnowledge(options?)

Mock the knowledge module.

mockDatabase()

Mock the database client.

const db = mockDatabase();
db._queries; // Array<{ sql: string; params?: unknown[] }>

mockMonitor(options?)

Mock the monitor client.

mockWorkflow(options?)

Mock the workflow client.

mockLLM(options?) (legacy)

Mock the legacy v4 LLM client.

mockCache()

Mock the cache client.

mockDb() (legacy)

Legacy database mock.

CallTracker

All v5 mocks use a shared CallTracker pattern for call tracking:

const ai = mockAI({ text: 'Hello' });
await ai.generate('test');
await ai.generate('test 2');

expect(ai._tracker.callCount).toBe(2);
expect(ai._tracker.lastArgs).toEqual(['test 2', undefined]);
expect(ai._tracker.allArgs).toHaveLength(2);

Types

  • CallTracker — callCount, lastArgs, allArgs
  • MockAIOptions — text, texts, streamChunks, structuredResult, provider, model
  • MockChainOptions — result
  • MockAgentsOptions — result
  • MockKnowledgeOptions — chunks, searchResults
  • MockMonitorOptions — traceId
  • MockWorkflowOptions — jobResult
  • MockLLMOptions — legacy mock config
On this page

On this page