sinon
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@sinonjs/commons | 3.0.1 | 10.39 kB | BSD-3-Clause | prod | |
@sinonjs/fake-timers | 11.2.2 | 18.66 kB | BSD-3-Clause | prod | |
@sinonjs/samsam | 8.0.0 | 20.53 kB | BSD-3-Clause | prod | |
diff | 5.2.0 | 419.27 kB | BSD-3-Clause | prod | |
nise | 5.1.9 | 254.43 kB | BSD-3-Clause | prod | |
supports-color | 7.2.0 | 3.13 kB | MIT | prod |
Sinon is a standalone and testing-framework agnostic JavaScript library used for creating test spies, stubs and mocks. Designed to be easy to use and easily integrated with any testing framework, Sinon helps developers fake any interface and ships with ready-to-use fakes for XMLHttpRequest, timers and more, without causing global pollution.
Sinon can be installed via npm with the command npm install sinon
. It can also be accessed via its browser builds available for download on the homepage, or through the npm based CDNs available. However, the specific details on how to use Sinon depend on the needs of your project and the testing framework you are using. In general, you would use Sinon to create and manage spies, stubs, and mocks for your testing suite, a very high-level example might look something like this in your Javascript test file:
const sinon = require('sinon');
let callback = sinon.spy();
let proxy = new Proxy({}, {
get: function(target, property) {
if (property in target) {
return target[property];
} else {
callback(property);
return function() {};
}
}
});
proxy.hello();
console.log(callback.calledWith('hello')); // true
The main source for Sinon documentation is the Sinon project homepage. The official Sinon website contains a comprehensive guide on how to use Sinon, including usage examples and detailed explanations of concepts. In case of additional questions not covered by the documentation, one can check out the sinon
tag on Stack Overflow or drop by #sinon.js on irc.freenode.net:6667. The Sinon.JS mailing list archives can also provide valuable historical information and discussions about the package.