Spy

General

// Definition

A test double that wraps real behaviour and records calls, so the test can both let the real code run and inspect how it was used.

// Code Example

SinonSpy on a method to verify calls
TypeScript
import sinon from 'sinon';
import { logger } from './logger';

const spy = sinon.spy(logger, 'info');

doImportantWork();

expect(spy.calledOnce).toBe(true);
expect(spy.firstCall.args[0]).toBe('work complete');
spy.restore();

// Related terms