@squiz/tool-test-helpers
Test utilities for DXP AI Tools that use the ToolHandler signature from @squiz/dxp-tool-sdk.
Installation
npm install --save-dev @squiz/tool-test-helpers
Usage
callToolHandler
Helper function to test tool handlers with minimal parameters. Only input is required; all other parameters (config, system, session, logger) are mocked automatically.
import { callToolHandler } from '@squiz/tool-test-helpers';
import { handler } from './tool';
describe('My Tool', () => {
it('should work with minimal params', async () => {
const result = await callToolHandler(handler, {
input: { foo: 'bar' }
});
expect(result.success).toBe(true);
});
it('should work with custom logger', async () => {
const mockLogger = { error: jest.fn() };
const result = await callToolHandler(handler, {
input: { foo: 'bar' },
logger: mockLogger
});
expect(mockLogger.error).toHaveBeenCalled();
});
});
createMockToolHandlerParams
Creates full mock parameters for ToolHandler if you need more control:
import { createMockToolHandlerParams } from '@squiz/tool-test-helpers';
const params = createMockToolHandlerParams({
input: { foo: 'bar' },
config: {
id: 'custom-id',
name: 'Custom Tool',
}
});
Features
- ✅ Full TypeScript support
- ✅ Works with any ToolHandler signature
- ✅ Provides sensible defaults for all parameters
- ✅ Allows selective parameter override
- ✅ Mock logger included by default