Sinon.JS
Standalone test double library for JavaScript providing spies, stubs, mocks, and fake timers. Framework-agnostic — works with Mocha, Jasmine, Jest, AVA, or no framework. The original and most comprehensive JavaScript test double library before Jest's built-in mocking.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
BSD 3-Clause licensed. Test-only library. No production deployment concerns.
⚡ Reliability
Best When
You're using Mocha, Chai, or another non-Jest test framework and need comprehensive test doubles (spies, stubs, mocks, fake timers) in one library.
Avoid When
You're using Jest — Jest's built-in mocking is sufficient and integrates more seamlessly. For ESM projects, Sinon's ESM support is incomplete.
Use Cases
- • Stub agent dependencies (database clients, HTTP services, file system) with controlled return values in Mocha tests
- • Spy on function calls to verify agent code calls external services with correct parameters
- • Use fake timers to test agent code with setTimeout/setInterval without waiting for real time in tests
- • Create stubs that throw specific errors to test agent error handling code paths
- • Mock callback-based APIs in agent tests with controlled async behavior
Not For
- • Jest users — Jest has built-in mocking (jest.fn(), jest.mock()); Sinon adds unnecessary duplication in Jest projects
- • ES module mocking — Sinon struggles with ES module import mocking; use jest.mock() or vitest's vi.mock() for ESM
- • TypeScript-first projects — sinon-chai and TypeScript types are not as comprehensive as Jest's built-in TypeScript support
Interface
Authentication
Local testing library — no authentication required. BSD 3-Clause licensed.
Pricing
BSD 3-Clause licensed. Zero cost.
Agent Metadata
Known Gotchas
- ⚠ Always use sandbox and call sandbox.restore() in afterEach — forgetting restore() causes test pollution where stubs persist across tests
- ⚠ sinon.useFakeTimers() replaces Date, setTimeout, setInterval globally — must call clock.restore() in afterEach; affects ALL timers in the process
- ⚠ Stub must be on an object property — sinon.stub(myObject, 'methodName') not sinon.stub(myStandaloneFunction) — free function stubs require different approach
- ⚠ ES module stubs are not supported natively — Sinon can't stub ES module named exports; use dependency injection, proxyquire, or Jest for ES module mocking
- ⚠ Mock expectations are verified on mock.verify() — must call explicitly; Sinon mocks don't auto-verify at test end unlike some other mock frameworks
- ⚠ sinon.spy() wraps but calls the original — sinon.stub() replaces; understand the difference: spy observes, stub controls behavior
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for Sinon.JS.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-07.