import { MOCK_SYMBOL, MockCall } from "./_mock_util.ts";
export function fn(...stubs: Function[]): Function { const calls: MockCall[] = [];
const f = (...args: any[]) => { const stub = stubs.length === 1 ? stubs[0] : stubs[calls.length];
try { const returned = stub ? stub(...args) : undefined; calls.push({ args, returned, timestamp: Date.now(), returns: true, throws: false, }); return returned; } catch (err) { calls.push({ args, timestamp: Date.now(), returns: false, thrown: err, throws: true, }); throw err; } };
Object.defineProperty(f, MOCK_SYMBOL, { value: { calls }, writable: false, });
return f;}