Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Created May 17, 2016 07:08
Show Gist options
  • Save wolframkriesing/311b8b84289571d6fbe11d0a8e815d2c to your computer and use it in GitHub Desktop.
Save wolframkriesing/311b8b84289571d6fbe11d0a8e815d2c to your computer and use it in GitHub Desktop.
export const buildFunctionSpy = ({ returnValue = void 0 } = {}) => {
const spy = (...args) => {
spy.wasCalled = true;
spy.lastCallArgs = args;
spy.allCallsArgs.push(args);
spy.callCount++;
return returnValue;
};
spy.wasCalled = false;
spy.lastCallArgs = null;
spy.allCallsArgs = [];
spy.callCount = 0;
return spy;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment