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.

Evaluated Mar 07, 2026 (0d ago) v17.x / 18.x
Homepage ↗ Repo ↗ Developer Tools testing mocking stubs spies fakes node browser jest-alternative
⚙ Agent Friendliness
68
/ 100
Can an agent use this?
🔒 Security
98
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
88
Error Messages
82
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
85
Secret Handling
100

BSD 3-Clause licensed. Test-only library. No production deployment concerns.

⚡ Reliability

Uptime/SLA
100
Version Stability
88
Breaking Changes
85
Error Recovery
88
AF Security 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

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no authentication required. BSD 3-Clause licensed.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

BSD 3-Clause licensed. Zero cost.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

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

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-07.

6470
Packages Evaluated
26150
Need Evaluation
173
Need Re-evaluation
Community Powered