Testing Installation
Installation
Section titled “Installation”Add @llmist/testing as a dev dependency:
bun add -D @llmist/testingnpm install -D @llmist/testingpnpm add -D @llmist/testingyarn add -D @llmist/testingTest Setup
Section titled “Test Setup”With Vitest
Section titled “With Vitest”import { beforeEach } from 'vitest';import { getMockManager } from '@llmist/testing';
beforeEach(() => { // Clear all registered mocks before each test getMockManager().clear();});Configure in vitest.config.ts:
import { defineConfig } from 'vitest/config';
export default defineConfig({ test: { setupFiles: ['./test/setup.ts'], },});With Jest
Section titled “With Jest”import { getMockManager } from '@llmist/testing';
beforeEach(() => { getMockManager().clear();});Configure in jest.config.js:
module.exports = { setupFilesAfterEnv: ['./test/setup.ts'],};Basic Usage Pattern
Section titled “Basic Usage Pattern”-
Import testing utilities
import { mockLLM, createMockClient } from '@llmist/testing'; -
Register mock responses
mockLLM().forAnyModel().whenMessageContains('hello').returns('Hi there!').register(); -
Create a mock client
const client = createMockClient(); -
Run your agent
const response = await client.createAgent().withModel('sonnet').askAndCollect('hello world'); -
Assert on the response
expect(response).toContain('Hi there!');
Next Steps
Section titled “Next Steps”Now that you have testing set up, continue to the Quick Start to write your first mock test!