Website profiles · Technology insights · Alternatives

sinonjs.org

A library for stubbing, spying, and mocking in JavaScript tests. Works with any unit testing framework.

No paid content found
Visit website
Profile views 17 Outbound visits 5 Normal
SinonJS Full homepage screenshot

At a glance

Category
Development
Language
English
Paid-content signal
No paid content foundObserved
Registered
2010
Hosting
FastlyInferred
HTTPS certificate trusted
PassedObserved
Last updated

Website review

This review may include AI-generated content and is not individually verified. Domain, certificate and other facts come from the observed data on this page.

What is SinonJS?

SinonJS is a JavaScript library for creating test doubles: stubs, spies, mocks and fake timers. It works alongside any unit testing framework, so it is typically adopted as a complement to tools like Jest, Mocha or QUnit rather than as a replacement for them. See SinonJS.

What it is used for

  • Spies record how a function was called without changing its behaviour, which helps verify interactions.
  • Stubs replace a function's behaviour, letting you force return values, throw errors or assert call arguments.
  • Mocks combine expectations about calls with behaviour, useful when you want a test to fail on unexpected interactions.
  • Fake timers control setTimeout, setInterval and similar APIs, which suits testing debouncing, polling or time-dependent logic.
  • Fake servers and XHR/fetch helpers intercept network requests so tests can run without a live backend.

Who it suits and trade-offs

It fits developers writing isolated unit tests in Node.js or the browser, especially when dependencies such as HTTP clients, clocks or third-party modules need to be controlled. The main trade-off is that heavy stubbing can make tests tightly coupled to implementation details, so they break when code is refactored even if behaviour is unchanged. Sinon is unopinionated about assertions and runners, which offers flexibility but means more setup choices than an all-in-one framework.

How do I stub a function with SinonJS?

Stubbing replaces a function's behavior during a test so you can control what it returns and verify how it was called. In SinonJS, the common entry point is sinon.stub(), which works alongside any unit testing framework.

Basic pattern

A typical flow is:

  1. Identify the object and method you want to replace, for example api.fetchUser.
  2. Create a stub with const stub = sinon.stub(api, "fetchUser").
  3. Configure behavior: stub.returns({ id: 1 }), stub.resolves(data) for promises, or stub.throws(new Error("fail")).
  4. Run the code under test.
  5. Assert on the stub, such as stub.calledOnce or stub.calledWith(42).
  6. Restore the original with stub.restore() or a sandbox.

Sandboxes and cleanup

For multiple stubs, sinon.createSandbox() groups them so a single sandbox.restore() resets everything. This is suited to test suites where leaked stubs would affect later cases.

Trade-offs

Stubbing isolates the unit under test and makes edge cases like errors or slow responses easy to simulate. However, over-stubbing can couple tests to implementation details, so they break when internals change even if behavior stays correct. Prefer stubbing boundaries such as network calls or clocks, and keep assertions focused on observable outcomes.

The official documentation at SinonJS covers fakes, spies and matchers in more depth.

How do I spy on a method with SinonJS?

To spy on a method with SinonJS, wrap the object's method in sinon.spy(). The spy records how the method is called while letting the original implementation run by default.

Basic pattern

const spy = sinon.spy(object, "method");
object.method(42);
console.log(spy.calledOnce); // true
console.log(spy.calledWith(42)); // true

For a standalone function:

const spy = sinon.spy(myFunction);

What spies capture

  • Call count: called, callCount, calledOnce, calledTwice
  • Arguments: calledWith, args, firstCall.args
  • Context and return value: thisValue, returned
  • Call order: calledBefore, calledAfter

Spying vs. stubbing

sinon.spy() sinon.stub()
Calls original Yes, by default No, unless you call through
Changes behavior No Yes
Best for Verifying interactions Isolating dependencies

Use a spy when you want to observe a real method without altering it; use a stub when you need to replace the behavior. Both work with any unit testing framework, including Mocha, Jest and QUnit, so you can add them to an existing suite without switching runners.

Restore spies after each test with spy.restore() or a sandbox to avoid leaking state between tests. See SinonJS for the full API.

Can SinonJS be used with any unit testing framework?

SinonJS is designed to be test-framework agnostic. Its stubs, spies, mocks and fake timers are plain JavaScript objects and functions that do not depend on a particular runner's internals. Because of that, it can typically be dropped into suites written for Jest, Mocha, Jasmine, QUnit, Vitest, or a custom harness, as long as the environment supports the JavaScript features Sinon uses.

That flexibility matters when you are:

  • Migrating between test runners and want to keep assertion helpers and fake timers working.
  • Testing legacy code where the runner is fixed but you need to replace network calls or Date.
  • Writing framework-agnostic utility tests that must run in several environments.

The main trade-off is integration depth. Jest, for example, ships its own mocking and timer APIs, so mixing them with Sinon can create confusion about which fake clock or mock registry is active. Sinon also restores behaviour manually, so you usually need sinon.restore() in an afterEach hook; some runners do this automatically for their built-in tools.

For documentation and setup guidance, see SinonJS. If you want to compare it with a runner's native mocking, look at Jest or Mocha.

What is the difference between stubbing, spying, and mocking in SinonJS?

In SinonJS, stubbing, spying and mocking are three related ways to replace or observe behaviour in JavaScript tests. They differ mainly in how much control they give you and what they are designed to verify.

Spies

A spy wraps an existing function and records how it was called without changing its behaviour. You use spies when you want to observe calls, arguments, return values or this context while the real logic still runs. They suit tests that check whether a function was invoked correctly.

Stubs

A stub replaces a function entirely. You control what it returns, what it throws, or how it behaves, and it also records call information like a spy. Stubs are useful for isolating the code under test from dependencies such as network calls, timers or databases, and for forcing specific edge cases.

Mocks

A mock is a fake object with pre-programmed expectations. Instead of asserting after the fact, you set expectations on the mock and then verify them. Mocks suit tests where you want to assert that a set of interactions happened in a specific way, though they can make tests more brittle than stubs.

Tool Replaces behaviour Records calls Typical use
Spy No Yes Observing real functions
Stub Yes Yes Isolating dependencies, forcing outcomes
Mock Yes Yes, with expectations Verifying interaction contracts

All three work with any unit testing framework, so the choice typically depends on whether you need observation, control, or expectation-based verification. See SinonJS for details.

How do I create a mock object with SinonJS?

To create a mock object in SinonJS, you typically use sinon.mock(). A mock wraps an existing object and lets you set expectations about how its methods should be called before the code under test runs.

A minimal pattern looks like this:

const mock = sinon.mock(myObject);
mock.expects("myMethod").once().withArgs("value");
// run code that calls myObject.myMethod("value")
mock.verify();

Key points:

  • sinon.mock(obj) returns a mock for obj; it does not replace the object itself.
  • mock.expects("method") defines an expectation and returns an expectation object you can refine.
  • Common refinements include .once(), .twice(), .never(), .withArgs(...), and .returns(...).
  • mock.verify() checks that all expectations were satisfied; it usually throws if not.
  • mock.restore() removes the mock behavior, typically in cleanup.

Mocks differ from spies and stubs. A spy observes calls without changing behavior by default; a stub replaces behavior. A mock combines replacement with built-in expectations and verification, which suits tests where the interaction contract matters as much as the result.

Because SinonJS works with any unit testing framework, you can use mocks alongside Mocha, Jest, or others, though Jest also offers its own mocking utilities. For full API details, see SinonJS.

Related questions

More questions →
What is sinonjs.org?
A library for stubbing, spying, and mocking in JavaScript tests. Works with any unit testing framework.
Does sinonjs.org offer paid content?
Unknown.
What languages does sinonjs.org support?
Primary language: English.
How can I visit sinonjs.org?
Use the Visit website link to open the website in a new tab.
What are some alternatives to sinonjs.org?
Related websites include zzzcode.ai, zyte.com, zustand.docs.pmnd.rs, zustand-demo.pmnd.rs, zulko.github.io, zmk.dev. Compare their features and pricing for your needs.

Website Overview

Identifiable technologies and additional version or configuration signals make the service easier to fingerprint, which may help targeted scanners narrow their checks. An established domain and managed infrastructure suggest continuity of operations and may support dependable delivery, although neither guarantees service quality.

Domain and Registration

Registered in 2010, this domain has about 15 years of history. That suggests continuity, although ownership and purpose may have changed. Transfer-protection status is present, helping reduce the risk of unauthorized domain transfers. The domain uses the common .org extension, which is not an independent safety signal.

DNS and Email

The observed email authentication setup is incomplete: SPF is missing. Nameservers are provided by hyp.net, indicating managed DNS hosting. MX records point to the Google Workspace email service. DNSSEC is enabled, allowing validating resolvers to authenticate signed DNS data. No CNAME was found; the observed records resolve directly to addresses.

TLS and Certificates

The certificate uses an RSA 2048-bit public key, offering broad client compatibility. The server supplied a complete certificate chain. No organization name is present in the certificate; the available fields are consistent with domain validation. The certificate was issued by Let's Encrypt, commonly associated with automated certificate services. The certificate's total validity is about 89 days, consistent with a short renewal cycle.

HTTP and Browser Security

The checked browser-security headers were not detected, leaving fewer explicit browser-side safeguards. CORS permits any origin to read this response. This is common for public resources; sensitive responses need narrower handling. No X-Powered-By header was found, reducing one common source of backend fingerprinting information. The x-cache, x-served-by, via response header indicates a CDN or caching proxy in the delivery path. No obvious internal addresses or debug information were found in the headers.

Technology Stack Analysis

The public page identifies VitePress 2.0.0-alpha.17, Fastly, with exact versions exposed for 1 technologies. These details can narrow vulnerability checks, although exposure alone is not a vulnerability.

Search and Social Sharing

The Generator tag identifies VitePress v2.0.0-alpha.17, making the publishing system easier to fingerprint. No homepage canonical URL was detected. If duplicate URLs exist, consolidation may be less explicit. No Open Graph metadata was detected, so social previews may depend on platform inference. The title has 18 characters, within a common display range. A meta description is present, with 103 characters.

Hosting and Email

DNShyp.net
HostingFastly
EmailGoogle Workspace
Approximate IP geolocation (inferred; a CDN or proxy may differ from the origin server) United States flagUnited States Inferred 185.199.108.153

Registration details

RDAP / WHOIS

RegistrarDomeneshop AS dba domainnameshop.com
Registered2010-12-27
Expires2026-12-27
Domain statusclient transfer prohibited
Nameserversns1.hyp.net、ns2.hyp.net、ns3.hyp.net
DNSSECsigned

DNS records

DNS

TypeNameValueTTLPriority
Asinonjs.org185.199.108.1533600—
Asinonjs.org185.199.109.1533600—
Asinonjs.org185.199.110.1533600—
Asinonjs.org185.199.111.1533600—
AAAAsinonjs.org2606:50c0:8000::1533600—
AAAAsinonjs.org2606:50c0:8001::1533600—
AAAAsinonjs.org2606:50c0:8002::1533600—
AAAAsinonjs.org2606:50c0:8003::1533600—
MXsinonjs.orgASPMX.L.GOOGLE.COM36001
MXsinonjs.orgALT1.ASPMX.L.GOOGLE.COM36005
MXsinonjs.orgALT2.ASPMX.L.GOOGLE.COM36005
MXsinonjs.orgALT3.ASPMX.L.GOOGLE.COM360010
MXsinonjs.orgALT4.ASPMX.L.GOOGLE.COM360010
NSsinonjs.orgns1.hyp.net86400—
NSsinonjs.orgns2.hyp.net86400—
NSsinonjs.orgns3.hyp.net86400—
DSsinonjs.org19536 15 2 45317dffa6512af0a3816b56f5712109443a34fe15f67f2f482c4f259c5b6dd43600—
DSsinonjs.org19536 15 4 60d73e1525f288d4db9a661e81c521afdef0106bb3b9336d258665b84385065aeed40626b10e4552719d17f85ae5125b3600—
DMARC_dmarc.sinonjs.orgv=DMARC1; p=none3600—

TLS and certificates

TLS / SSL

AssessmentNormal configuration
Supported protocolsTLSv1.2、TLSv1.3
Negotiated protocolTLSv1.3
Certificate subjectsinonjs.org
IssuerLet's Encrypt
Valid until2026-11-20T10:48 · Remaining when checked: 59 days
Verification detailsCertificate trust: Passed · Hostname match: Passed

HTTP response headers

HTTP

HeaderValue
content-typetext/html; charset=utf-8
cache-controlmax-age=600
serverGitHub.com
access-control-allow-origin*

Identified technologies

VitePress 2.0.0-alpha.17Fastly

Pages, Search and Sharing

Meta descriptionA library for stubbing, spying, and mocking in JavaScript tests. Works with any unit testing framework.
Canonical URLNot detected
LanguageEnglish (default)
Twitter CardNot detected

Unknown

All bots 1 allowed · 0 disallowed
  • Allow/

User reviews (0)

  • No reviews yet.