Skip to content

Testing Installation

Add @llmist/testing as a dev dependency:

Terminal window
bun add -D @llmist/testing
test/setup.ts
import { beforeEach } from 'vitest';
import { getMockManager } from '@llmist/testing';
beforeEach(() => {
// Clear all registered mocks before each test
getMockManager().clear();
});

Configure in vitest.config.ts:

vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
setupFiles: ['./test/setup.ts'],
},
});
test/setup.ts
import { getMockManager } from '@llmist/testing';
beforeEach(() => {
getMockManager().clear();
});

Configure in jest.config.js:

jest.config.js
module.exports = {
setupFilesAfterEnv: ['./test/setup.ts'],
};
  1. Import testing utilities

    import { mockLLM, createMockClient } from '@llmist/testing';
  2. Register mock responses

    mockLLM()
    .forAnyModel()
    .whenMessageContains('hello')
    .returns('Hi there!')
    .register();
  3. Create a mock client

    const client = createMockClient();
  4. Run your agent

    const response = await client.createAgent()
    .withModel('sonnet')
    .askAndCollect('hello world');
  5. Assert on the response

    expect(response).toContain('Hi there!');

Now that you have testing set up, continue to the Quick Start to write your first mock test!