# sinonjs/sinon

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/sinonjs-sinon).**

9,754 stars · 790 forks · JavaScript · NOASSERTION

## Links

- GitHub: https://github.com/sinonjs/sinon
- Homepage: https://sinonjs.org/
- awesome-repositories: https://awesome-repositories.com/repository/sinonjs-sinon.md

## Description

Sinon is a JavaScript test double library and mocking framework used to isolate code and verify behavior during unit testing. It provides a collection of spies, stubs, and mocks that replace real function implementations and object methods with controlled substitutes.

The project includes a specialized fake timer library for overriding the system clock, allowing the simulation of time progression to trigger timeouts and intervals without waiting for real-time delays. It also features a test sandbox mechanism to group multiple fakes together, ensuring the original state is restored between test cases to prevent environment leakage.

The toolkit covers a broad range of verification capabilities, including recording function call arguments and invocation counts, simulating dependency behaviors through predefined return values or errors, and verifying object interactions. It further supports intercepting network requests and stubbing object instances and accessors.

## Tags

### Testing & Quality Assurance

- [Mocking Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/mocking-frameworks.md) — Serves as a comprehensive framework for creating simulated objects and stubbing method calls.
- [Fake Timers](https://awesome-repositories.com/f/testing-quality-assurance/fake-timers.md) — Trigger timeouts and intervals instantly by replacing the system clock with a fake timer to avoid waiting for real time. ([source](https://github.com/sinonjs/sinon#readme))
- [Function Call Tracking](https://awesome-repositories.com/f/testing-quality-assurance/function-call-tracking.md) — Maintains an internal ledger of arguments, contexts, and return values for every invocation of a wrapped function.
- [Function Behavior Replacement](https://awesome-repositories.com/f/testing-quality-assurance/function-call-tracking/function-behavior-replacement.md) — Simulates specific dependencies by intercepting function calls and returning predefined values or throwing errors. ([source](https://github.com/sinonjs/sinon/blob/main/package.json))
- [Test Isolation](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-isolation.md) — Prevents test leakage by grouping multiple fakes into a sandbox that restores the original state. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))
- [Global Object Interception](https://awesome-repositories.com/f/testing-quality-assurance/global-object-interception.md) — Implements the replacement of native JavaScript clock and timer functions to simulate time progression.
- [Mocking and Spying Libraries](https://awesome-repositories.com/f/testing-quality-assurance/mocking-and-spying-libraries.md) — Provides a full toolkit of spies, stubs, and mocks for isolation and interaction tracking.
- [Object Interaction Verification](https://awesome-repositories.com/f/testing-quality-assurance/object-interaction-verification.md) — Checks that specific methods on an object are called with expected arguments and in the correct order. ([source](https://github.com/sinonjs/sinon/blob/main/package.json))
- [Dependency Mocking](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking.md) — Replaces module dependencies and network calls with controlled substitutes to simulate specific behaviors.
- [Timer Mocks](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking/timer-mocks.md) — Allows overriding native timers to control time-based execution and trigger timeouts instantly. ([source](https://github.com/sinonjs/sinon/blob/main/README.md))
- [Test Sandbox Restoration](https://awesome-repositories.com/f/testing-quality-assurance/test-sandbox-restoration.md) — Ships a sandbox mechanism that tracks all modified properties and restores original behavior via a single cleanup call.
- [Test Spying Utilities](https://awesome-repositories.com/f/testing-quality-assurance/test-spying-utilities.md) — Tracks function call arguments, return values, and invocation counts to verify object interactions.
- [Virtual Time Testing](https://awesome-repositories.com/f/testing-quality-assurance/virtual-time-testing.md) — Simulates the passage of time by overriding the system clock to trigger timers without waiting in real-time. ([source](https://github.com/sinonjs/sinon/blob/main/package.json))
- [API Request Mocking](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/network-api-mocking/api-request-mocking.md) — Mocks server responses and inspects outgoing requests by simulating a network environment. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))
- [Test State Sandboxes](https://awesome-repositories.com/f/testing-quality-assurance/javascript-testing-frameworks/test-state-sandboxes.md) — Includes a sandbox mechanism to group fakes and automatically restore original behavior between tests.
- [Instance-Level Stubbing](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/assertions-and-validation/test-case-definitions/method-stubbing-utilities/instance-level-stubbing.md) — Replaces every method in a constructor instance with a stub to simulate a full object. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))
- [Instance Stubbing](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/assertions-and-validation/test-case-definitions/method-stubbing-utilities/instance-stubbing.md) — Provides the ability to intercept object instantiation and automatically stub every method of the resulting instance.
- [Unit Testing](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/unit/unit-testing.md) — Provides the essential tooling for isolating units of code and verifying their logic in JavaScript.

### DevOps & Infrastructure

- [Controlled Interface Fakes](https://awesome-repositories.com/f/devops-infrastructure/infrastructure-state-management-systems/in-memory-fakes/controlled-interface-fakes.md) — Allows replacing function implementations to return specific values or trigger errors for controlled testing. ([source](https://github.com/sinonjs/sinon#readme))
- [Test Double Implementations](https://awesome-repositories.com/f/devops-infrastructure/infrastructure-state-management-systems/in-memory-fakes/test-double-implementations.md) — Implements a comprehensive set of spies, stubs, and mocks to replace real dependencies. ([source](https://github.com/sinonjs/sinon/blob/main/README.md))

### Programming Languages & Runtimes

- [Argument Constraint Matchers](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/function-utilities/argument-collectors/splat-argument-validations/argument-constraint-matchers.md) — Provides logic for validating function call arguments against custom predicates and constraints during assertions.
- [Fake Timer Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/javascript-utility-libraries/fake-timer-utilities.md) — Offers a specialized library to override the system clock for instant timeout and interval triggering.
- [Mock Expectation Definitions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/core-conceptual-frameworks/programming-language-concepts/method-definitions/mock-expectation-definitions.md) — Provides syntax for defining anticipated method calls and return sequences on mock objects. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))

### Software Engineering & Architecture

- [Method Interception Proxies](https://awesome-repositories.com/f/software-engineering-architecture/method-interception-proxies.md) — Uses dynamic proxy systems to wrap original methods and record metadata or control return values.
- [Test-Time](https://awesome-repositories.com/f/software-engineering-architecture/smart-contract-libraries/function-overrides/test-time.md) — Returns specific values, throws errors, or resolves promises by overriding existing functions. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))

### System Administration & Monitoring

- [Interaction Verification Utilities](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/diagnostic-error-reporting/method-call-verification/interaction-verification-utilities.md) — Enables recording and asserting that object methods are called with expected arguments and in the correct order.

### Data & Databases

- [Accessor Stubbing](https://awesome-repositories.com/f/data-databases/object-property-accessors/accessor-stubbing.md) — Controls or monitors access to specific properties by replacing getters and setters on objects. ([source](https://github.com/sinonjs/sinon/blob/main/CHANGES.md))

### Part of an Awesome List

- [Testing and Quality Assurance](https://awesome-repositories.com/f/awesome-lists/devtools/testing-and-quality-assurance.md) — Test spies, stubs, and mocks for JavaScript.
- [Testing Frameworks](https://awesome-repositories.com/f/awesome-lists/devtools/testing-frameworks.md) — Mocking library with spies, stubs, and mocks.
