# @salesforce/ts-sinon

> TypeScript helpers for Sinon

Latest version **1.4.45** (published 2026-11-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @salesforce/ts-sinon
pnpm add @salesforce/ts-sinon
yarn add @salesforce/ts-sinon
bun add @salesforce/ts-sinon
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.4.45 |
| Published | 2026-11-09 |
| First published | 2018-09-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Salesforce |
| Maintainers | ire-npm-team-user, jimjag, salesforce-releases, jasonschroeder-sfdc, mobify, lwc-admin, salesforce-admin |

## Links

- npm: https://www.npmjs.com/package/@salesforce/ts-sinon
- Repository: https://github.com/forcedotcom/ts-sinon
- Homepage: https://github.com/forcedotcom/ts-sinon#readme
- Issues: https://github.com/forcedotcom/ts-sinon/issues
- npm.io page: https://npm.io/package/@salesforce/ts-sinon

## Dependencies (3)

- [sinon](https://npm.io/package/sinon.md) ^5.1.1
- [tslib](https://npm.io/package/tslib.md) ^2.9.1
- [@salesforce/ts-types](https://npm.io/package/@salesforce/ts-types.md) ^2.0.12

## Recent versions

- 1.4.45 (latest) — 2026-11-09
- 1.4.44 — 2026-11-09
- 1.4.43 — 2026-11-08
- 1.4.42 — 2026-11-08
- 1.4.41 — 2026-11-08
- 1.4.39 — 2026-10-09
- 1.4.38 — 2026-10-09
- 1.4.37 — 2026-09-28
- 1.4.36 — 2026-06-17
- 1.4.35 — 2026-06-17
- 1.4.34 — 2026-04-10
- 1.4.33 — 2026-03-26
- 1.4.32 — 2026-03-26
- 1.4.31 — 2025-08-29
- 1.4.30 — 2024-11-17
- … 70 more at https://npm.io/package/@salesforce/ts-sinon/versions

## README

# TypeScript-friendly utils for Sinon testing

This is a simple library to help create stubs with Sinon when working with TypeScript in order to leverage Sinon stubs and the type system more completely together as one without resorting to ugly, untyped hacks like casting stubbed functions to `any` or using associative array accesses, neither of which provide IDE-autocompletion of stub properties and methods, nor work well with stricter `tsc` and `tslint` rules applied to test sources.

## API

The API consists of the following functions:

### stubInterface

Used to provide a fully stubbed interface backed by an optional set of member properties which may form a subset of the overall interface. Function properties will be typed as proper `SinonStub`s along with any other specific type information provided by the interface.

### stubObject

Returns a fully stubbed proxy similar to those provided by `stubInterface`, but backed first by the optionally given members, and finally by a given object. This is useful for stubbing some properties of an existing object while providing test-specific returns for fakes for others.

### stubCallable

Like `stubObject` but works with callable TypeScript function types (i.e., functions with properties).

### fromStub

When using `stubObject` with objects created from classes with non-public members, the resulting `StubbedType<T>` often needs to be passed to a function or constructor that expects a `T`, but TypeScript's mapped types (which are the basis of `StubbedType`) do not capture non-public class members. Since the `StubbedType` returned from `stubObject` is backed by a real instance of type `T`, it can be simply reverted to type `T` by using `fromStub(instance)`. The implementation of this simply applies a type assertion, but using `fromStub` is preferred for clarity, especially given that this library exists to reduce the necessity of using type assertions in tests in the first place.

---
_Source: https://npm.io/package/@salesforce/ts-sinon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
