Implement solve(op, ...args) that simulates jest.fn():
| Op | Args | Returns |
|---|---|---|
'create' | (returnValue?) | spy ID (integer). Creates a new spy that returns returnValue when called. If omitted, returns undefined. |
'call' | (id, ...callArgs) | The spy's configured return value. Records the call. |
'getCalls' | (id) | Array of all calls: [{ args: [...], returnValue }] |
'getCallCount' | (id) | Number of times the spy was called. |
'mockReturnValue' | (id, value) | Updates the return value for future calls. Returns undefined. |
'reset' | (id) | Clears call history. Returns undefined. |
Spies are stored in module-level state (the judge runs all test cases in one execution).
const id = solve('create', 42) // creates spy returning 42
solve('call', id, 'a', 'b') // calls spy with args ['a','b'], returns 42
solve('getCallCount', id) // 1
solve('getCalls', id)
// [{ args: ['a', 'b'], returnValue: 42 }]
solve('mockReturnValue', id, 99)
solve('call', id) // returns 99
solve('reset', id)
solve('getCallCount', id) // 0Sample tests