Sinon.JS
Standalone test spies, stubs, and mocks for JavaScript
About Sinon.JS
Sinon.JS is a powerful testing framework that works with any unit testing framework. It provides tools like spies, stubs, and mocks to simplify testing JavaScript applications. Whether you're testing callbacks, Ajax requests, or time-sensitive logic, Sinon.JS offers flexible solutions to isolate and verify behavior without complex setup.
FAQ
You can install Sinon.JS using npm by running the command: npm install sinon.
For Node and CommonJS build systems, you can require Sinon using: var sinon = require("sinon"); For direct browser use, include the script: . For ES6 Modules, use: import sinon from "./node_modules/sinon/pkg/sinon-esm.js"; .
Sinon.JS provides fake timers to test time-sensitive logic. You can use sinon.useFakeTimers() to create a clock and sinon.restore() to restore the original timers after your test.
You can use sinon.replace() to replace the jQuery.ajax method with a fake in your test. After your test, restore the original method using sinon.restore().
You can get help by joining the discussion on Stack Overflow or visiting the IRC channel #sinon.js on freenode.
Yes, Sinon.JS is released under the BSD license, which means it is free to use.
Alternatives to consider
Community ratings & full listBadges
Promote Sinon.JS giving it more exposure, by adding these badges to your website, documentation, or product listing. Each badge links back to Sinon.JS page on Webfolio.
<a href="https://www.webfolio.to/tools/sinon-js?utm_source=badge&utm_campaign=badge" target="_blank" rel="noopener noreferrer"><img src="https://www.webfolio.to/badges/featured_color.svg" alt="Featured on Webfolio" style="max-width: 150px" /></a>
Categories
Claim this tool
Are you the founder? Claim your profile to update details and track views.