Skip to content

@jaypie/testkit

Test utilities and mocks for Jaypie applications.

@jaypie/testkit provides comprehensive testing utilities, including:

  • Mocks for all Jaypie services
  • Custom Vitest matchers
  • Test helpers and utilities
  • Mock creation utilities
Terminal window
npm install --save-dev @jaypie/testkit

Complete mocking system for all Jaypie services:

import { mock } from "@jaypie/testkit";
// Mock LLM
mock.Llm.operate();
// Mock Express handler
const app = mock.expressHandler(handler);
// Mock Datadog metrics
mock.submitMetric();

Vitest matchers for Jaypie-specific assertions:

import { toThrowJaypieError } from "@jaypie/testkit";
expect.extend({ toThrowJaypieError });
expect(() => {
throw new BadRequestError("Invalid input");
}).toThrowJaypieError(BadRequestError);

Create custom mocks with fallback behavior:

import { createMockWrappedFunction } from "@jaypie/testkit";
const mockFn = createMockWrappedFunction(originalFn, {
fallback: "default value",
});

Mock logger for testing logging behavior:

import { mockLogFactory, spyLog, restoreLog } from "@jaypie/testkit";
const mockLog = mockLogFactory();
spyLog(log);
// ... test code ...
restoreLog(log);

API documentation will be generated from TypeScript definitions.