Skip to main content

Practice ยท 1 of 3

Hand-Rolled Spy

Write makeSpy(impl) returning a function that records every call: spy.calls is an array of argument-arrays, newest last. If impl is provided, each call forwards to it and returns its result; without impl it returns undefined. Also record return values in spy.results, and add spy.reset() which clears calls.

Difficulty: intermediate

Back to lesson: Practice: Seams & Doubles โ€” Practice