@ordojs/core
Version:
Core compiler and runtime for OrdoJS framework
117 lines • 3.23 kB
TypeScript
/**
* @fileoverview Server Function Mocking Utilities
*/
import type { MockServerFunction, ServerMockConfig } from './types.js';
/**
* Utilities for mocking server functions in tests
*/
export declare class ServerMockUtils {
private mocks;
private originalFetch?;
private rpcCallHistory;
constructor();
/**
* Mock a server function
*/
mockServerFunction(functionName: string, implementation: (...args: any[]) => any | Promise<any>, config?: Partial<ServerMockConfig>): MockServerFunction;
/**
* Create a mock function with configuration
*/
private createMockFunction;
/**
* Record RPC call for testing
*/
private recordCall;
/**
* Set up fetch mock to intercept RPC calls
*/
private setupFetchMock;
/**
* Get mock for a specific function
*/
getMock(functionName: string): MockServerFunction | undefined;
/**
* Check if a function was called
*/
wasCalled(functionName: string): boolean;
/**
* Get call count for a function
*/
getCallCount(functionName: string): number;
/**
* Get call arguments for a specific call
*/
getCallArgs(functionName: string, callIndex?: number): any[] | undefined;
/**
* Get last call arguments
*/
getLastCallArgs(functionName: string): any[] | undefined;
/**
* Get all call history for a function
*/
getCallHistory(functionName: string): Array<{
args: any[];
timestamp: number;
result?: any;
error?: Error;
}>;
/**
* Get complete RPC call history
*/
getRPCCallHistory(): Array<{
functionName: string;
args: any[];
timestamp: number;
result?: any;
error?: Error;
}>;
/**
* Clear mock for a specific function
*/
clearMock(functionName: string): void;
/**
* Clear all mocks
*/
clearAllMocks(): void;
/**
* Remove mock for a specific function
*/
removeMock(functionName: string): void;
/**
* Remove all mocks
*/
removeAllMocks(): void;
/**
* Restore original fetch
*/
restoreFetch(): void;
/**
* Create a mock server function with specific behavior
*/
createMockWithBehavior(config: ServerMockConfig): MockServerFunction;
/**
* Verify function was called with specific arguments
*/
verifyCalledWith(functionName: string, expectedArgs: any[]): boolean;
/**
* Verify function was called exactly n times
*/
verifyCallCount(functionName: string, expectedCount: number): boolean;
/**
* Verify function was never called
*/
verifyNeverCalled(functionName: string): boolean;
/**
* Deep equality check for arguments
*/
private deepEqual;
/**
* Create a spy that tracks calls without changing behavior
*/
spyOnServerFunction(functionName: string, originalImplementation: (...args: any[]) => any | Promise<any>): MockServerFunction;
/**
* Mock multiple server functions at once
*/
mockMultipleServerFunctions(configs: ServerMockConfig[]): MockServerFunction[];
}
//# sourceMappingURL=server-mock.d.ts.map