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

@types/sinon-chai

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/sinon-chai

TypeScript definitions for sinon-chai

  • 3.2.12
  • ts4.5
  • ts4.6
  • ts4.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @types/sinon-chai?

@types/sinon-chai is a TypeScript type definition package for the sinon-chai library, which provides Chai assertions for Sinon.js spies, stubs, and mocks. This package allows TypeScript developers to use sinon-chai with type safety and autocompletion in their projects.

What are @types/sinon-chai's main functionalities?

Spy Assertions

This feature allows you to assert that a spy was called once. The code sample demonstrates creating a spy on a method and then asserting that the method was called exactly once.

const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
const expect = chai.expect;

const myObj = {
  myMethod: function() {}
};

const spy = sinon.spy(myObj, 'myMethod');
myObj.myMethod();

expect(spy).to.have.been.calledOnce;

Stub Assertions

This feature allows you to assert that a stub was called and to check its return value. The code sample demonstrates creating a stub for a method, asserting that the stub was called, and verifying the return value.

const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
const expect = chai.expect;

const myObj = {
  myMethod: function() {
    return 'original';
  }
};

const stub = sinon.stub(myObj, 'myMethod').returns('stubbed');

expect(stub).to.have.been.called;
expect(myObj.myMethod()).to.equal('stubbed');

Mock Assertions

This feature allows you to create mocks and verify their expectations. The code sample demonstrates creating a mock for a method, setting an expectation, calling the method, and then verifying that the expectation was met.

const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
const expect = chai.expect;

const myObj = {
  myMethod: function() {}
};

const mock = sinon.mock(myObj);
mock.expects('myMethod').once();

myObj.myMethod();

mock.verify();

Other packages similar to @types/sinon-chai

FAQs

Package last updated on 07 Nov 2023

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