Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@salesforce/ts-sinon
Advanced tools
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.
The API consists of the following functions:
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.
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.
Like stubObject
but works with callable TypeScript function types (i.e., functions with properties).
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.
FAQs
TypeScript helpers for Sinon
The npm package @salesforce/ts-sinon receives a total of 21,116 weekly downloads. As such, @salesforce/ts-sinon popularity was classified as popular.
We found that @salesforce/ts-sinon demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.