Sinon.JS
Standalone test spies, stubs, and mocks for JavaScript
À propos de 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 à considérer
Voir toutes les alternativesBadges
Faites la promotion de Sinon.JS et donnez-lui plus de visibilité en ajoutant ces badges à votre site web, votre documentation ou votre fiche produit. Chaque badge renvoie vers la page de Sinon.JS sur 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="Mis en avant sur Webfolio" style="max-width: 150px" /></a>
Catégories
Revendiquer cet outil
Vous êtes le fondateur ? Revendiquez votre profil pour mettre à jour les détails et suivre les vues.