{
    "content": "<h1>Sinon.js API Overview<\/h1><p><a href=\"..\/Sinon.js\/\">Sinon.js<\/a> is a standalone <a href=\"..\/Unit Testing\/\">Unit Testing<\/a> library for <a href=\"..\/JavaScript\/\">JavaScript<\/a> that provides developers with the tools necessary to create <a href=\"..\/Test Double\/\">Test Double<\/a> objects. It is designed to work with any testing framework, including <a href=\"..\/Mocha\/\">Mocha<\/a>, <a href=\"..\/Jasmine\/\">Jasmine<\/a>, and <a href=\"..\/Jest\/\">Jest<\/a>, providing a robust set of features for isolating code under test.<\/p><h2>Core Functionalities<\/h2><p>The library is primarily composed of three types of test doubles:<\/p><ul><li><strong><a href=\"..\/Spies\/\">Spies<\/a>:<\/strong> A <a href=\"..\/Spies\/\">Spies<\/a> object records the arguments, return value, the value of <code>this<\/code>, and exceptions thrown for all its calls. It is used to verify that a function was called as expected without necessarily replacing its implementation.<\/li><li><strong><a href=\"..\/Stubs\/\">Stubs<\/a>:<\/strong> <a href=\"..\/Stubs\/\">Stubs<\/a> are <a href=\"..\/Spies\/\">Spies<\/a> with pre-programmed behavior. They are used to replace specific functions to return fixed values, throw errors, or call specific callbacks, which is essential for simulating edge cases or avoiding expensive operations like <a href=\"..\/Database\/\">Database<\/a> access.<\/li><li><strong><a href=\"..\/Mocks\/\">Mocks<\/a>:<\/strong> <a href=\"..\/Mocks\/\">Mocks<\/a> are similar to <a href=\"..\/Stubs\/\">Stubs<\/a> but come with built-in expectations. They define the expected interactions upfront and will fail the test if those expectations are not met.<\/li><\/ul><h2>Environment Simulation<\/h2><p>Beyond basic test doubles, <a href=\"..\/Sinon.js\/\">Sinon.js<\/a> offers advanced utilities for controlling the execution environment. <a href=\"..\/Fake Timers\/\">Fake Timers<\/a> allow developers to wrap the native clock functions (like <code>setTimeout<\/code>) to synchronously control the passage of time. Furthermore, <a href=\"..\/Fake XHR\/\">Fake XHR<\/a> and <a href=\"..\/Fake Server\/\">Fake Server<\/a> provide mechanisms to intercept and respond to <a href=\"..\/AJAX\/\">AJAX<\/a> and <a href=\"..\/HTTP\/\">HTTP<\/a> requests without a network connection.<\/p><p>Detailed technical specifications can be found at the <a href=\"https:\/\/sinonjs.org\/\">Official Sinon.js Documentation<\/a> and the project's <a href=\"https:\/\/github.com\/sinonjs\/sinon\">GitHub Repository<\/a>.<\/p><h3>Related Topics<\/h3><ul><li><a href=\"..\/Mocha\/\">Mocha<\/a><\/li><li><a href=\"..\/Chai\/\">Chai<\/a><\/li><li><a href=\"..\/Test Driven Development\/\">Test Driven Development<\/a><\/li><li><a href=\"..\/Assertion Libraries\/\">Assertion Libraries<\/a><\/li><\/ul>",
    "tags": [
        "sinonjs",
        "javascript",
        "unit testing",
        "spies",
        "stubs",
        "mocks",
        "test doubles",
        "tdd",
        "bdd",
        "web development"
    ]
}