Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-sinon

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-sinon

sinon library extension to stub whole object and interfaces

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
82K
decreased by-3.91%
Maintainers
1
Weekly downloads
 
Created

What is ts-sinon?

The ts-sinon package is a TypeScript-friendly wrapper around the Sinon.js library, which is used for creating spies, stubs, and mocks in JavaScript testing. It provides type-safe utilities that integrate seamlessly with TypeScript, making it easier to write tests with Sinon in TypeScript projects.

What are ts-sinon's main functionalities?

Spies

Spies are used to monitor the behavior of functions. In this example, a spy is created for a function, and after calling the function, we can check if it was called using `spy.called`.

const myFunction = () => {};
const spy = tsSinon.spy(myFunction);
spy();
console.log(spy.called); // true

Stubs

Stubs are used to replace functions with custom behavior. Here, a method of an object is stubbed to return a different value than it originally would.

const myObject = { myMethod: () => 'original' };
const stub = tsSinon.stub(myObject, 'myMethod').returns('stubbed');
console.log(myObject.myMethod()); // 'stubbed'

Mocks

Mocks are used to set expectations on function calls. In this example, a mock is created for an object's method, expecting it to be called once. The `verify` method checks if the expectations were met.

const myObject = { myMethod: () => {} };
const mock = tsSinon.mock(myObject);
mock.expects('myMethod').once();
myObject.myMethod();
mock.verify();

Other packages similar to ts-sinon

Keywords

FAQs

Package last updated on 16 Sep 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc