CheckOps
Sinon.JS
Sinon.JS is a BSD-3-Clause library of standalone test spies, stubs and mocks for JavaScript, plus fake timers and fake XHR/servers, and works with any test framework.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Sinon.JS provides standalone test spies, stubs and mocks for JavaScript. Because it is framework-agnostic, it is a common companion to Mocha and Chai, and also works with Jasmine, AVA, node:test and others. It is one of the most widely used JavaScript testing utilities, with nearly 10,000 GitHub stars.
Spies record how a function was called; stubs replace functions with programmable behaviour (returns, resolves, throws, callsFake); mocks add pre-programmed expectations. Sandboxes (sinon.createSandbox() or the default sandbox with sinon.restore()) make cleanup easy. Fake timers, from the companion @sinonjs/fake-timers package, control setTimeout, Date and other clocks, and Sinon’s fake XHR and fake server help test browser code that makes HTTP requests. Assertion helpers integrate with Chai via sinon-chai.
The source code is at sinonjs/sinon on GitHub under the BSD-3-Clause licence, with about 9,800 stars; the most recent commit was on 29 October 2026.
Sinon’s fake XHR and fake server remain useful for legacy browser code.
Features
- Spies, stubs and mocks: Record calls, replace behaviour and verify expectations.
- Sandboxes: Restore all fakes in one call.
- Fake timers: Control time with
sinon.useFakeTimers(). - Framework-agnostic: Works with Mocha, Jasmine, AVA, node:test and more.
Pros
- Free to use: Open source under the BSD-3-Clause licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 29 October 2026.
- Community: About 9,800 GitHub stars.
Cons
- Redundant with Jest/Vitest: Those frameworks include their own mocking.
- No module mocking: Replacing imported ES modules requires extra tools.
Usage and Links (Example)
npm install --save-dev sinon
import sinon from "sinon";
import assert from "node:assert/strict";
afterEach(() => sinon.restore());
it("retries once on failure", async () => {
const fetchUser = sinon.stub();
fetchUser.onFirstCall().rejects(new Error("timeout"));
fetchUser.onSecondCall().resolves({ id: 1 });
const user = await withRetry(fetchUser);
assert.equal(user.id, 1);
sinon.assert.calledTwice(fetchUser);
});
it("debounces", () => {
const clock = sinon.useFakeTimers();
const fn = sinon.spy();
debounce(fn, 100)();
clock.tick(100);
sinon.assert.calledOnce(fn);
});
Resources:
Pricing
Sinon.JS is free and open source under the BSD-3-Clause licence.
Recommended for?
- Mocha, Jasmine and node:test users who need test doubles.
- Teams testing timer-heavy code with fake timers.
Conclusion
Sinon.JS is the standard framework-agnostic test double library for JavaScript, especially valuable outside Jest and Vitest.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Sinon.JS side by side.
JJestJest is a free, open-source JavaScript test runner with zero-config defaults, mocks, and snapshot testing.Compare with Sinon.JS
VVitestVitest is a free, open-source unit test runner that reuses a Vite project's config, transforms, and plugins.Compare with Sinon.JS
MMochaMocha is a long-running, MIT-licensed JavaScript test framework for Node.js and browsers, with BDD and TDD interfaces, async support, hooks, parallel mode and a large reporter ecosystem.Compare with Sinon.JS
CChaiChai is an MIT-licensed BDD/TDD assertion library for Node.js and browsers, offering expect, should and assert styles and a large plugin ecosystem, pairing with any test framework.Compare with Sinon.JS
JJasmineJasmine is a long-established, MIT-licensed behaviour-driven JavaScript testing framework for browsers and Node.js, with built-in assertions, spies and asynchronous support and no required dependencies.Compare with Sinon.JS
MMock Service Worker (MSW)Mock Service Worker (MSW) is an MIT-licensed API mocking library that intercepts network requests at the network level in browsers (via a Service Worker) and Node.js, for REST, GraphQL and WebSocket APIs.Compare with Sinon.JS