How to use ClearRun mock mode in Jest or Vitest tests
Create the client with createKernelClient({ forceMock: true }) in your tests. It needs no key or network. Hosted scores work differently: a later run of the same text can score differently.
Last updated
Steps
Write a test
import { describe, it, expect } from 'vitest'; // or Jest globals import { createKernelClient } from '@clearrun/sdk'; describe('answer pipeline', () => { it('handles a verdict', async () => { const client = createKernelClient({ forceMock: true }); const { verdict } = await client.score({ responseText: 'Our API never stores customer data.' }); expect(verdict.verdictId.startsWith('mock_')).toBe(true); expect(typeof verdict.score).toBe('number'); }); });Fix the mock chat reply
const client = createKernelClient({ mock: { chatResponse: 'Fixed reply.' } });
Test error paths
To test 429 or 402 handling, pass your own fetch that returns that error. See How to pass your own fetch to the SDK (deps.fetch).
Don't assert real values
Mock scores depend only on text length. Test that your code handles the response shape. Do not assert on the mock score itself.