@salesforce/ts-sinon
TypeScript helpers for Sinon
Last updated 22 days ago by jgrantham .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @salesforce/ts-sinon 
SYNC missed versions from official npm registry.

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 SinonStubs 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.

Current Tags

  • 1.0.6                                ...           latest (22 days ago)

18 Versions

  • 1.0.6                                ...           22 days ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           5 months ago
  • 1.0.0                                ...           5 months ago
  • 0.2.10                                ...           5 months ago
  • 0.2.9                                ...           5 months ago
  • 0.2.8                                ...           5 months ago
  • 0.2.7                                ...           6 months ago
  • 0.2.6                                ...           6 months ago
  • 0.2.5                                ...           6 months ago
  • 0.2.4                                ...           6 months ago
  • 0.2.3                                ...           6 months ago
  • 0.2.2                                ...           7 months ago
  • 0.2.0                                ...           8 months ago
  • 0.1.0                                ...           8 months ago

Copyright 2014 - 2016 © taobao.org |