Socket
Book a DemoInstallSign in
Socket

sinon-chai

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon-chai

Extends Chai with assertions for the Sinon.JS mocking framework.

4.0.1
latest
Source
npmnpm
Version published
Weekly downloads
697K
-11.23%
Maintainers
3
Weekly downloads
 
Created

What is sinon-chai?

The sinon-chai npm package is an extension for the Chai assertion library that provides a set of custom assertions for Sinon.js spies, stubs, and mocks. It allows for more readable and expressive tests by integrating Sinon.js functionalities directly into Chai's BDD/TDD assertion styles.

What are sinon-chai's main functionalities?

Assert a spy was called

This feature allows you to assert that a Sinon.js spy was called. The code sample demonstrates how to create a spy on a method and then assert that the method was called using Chai's expect syntax.

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.called;

Assert a spy was called with specific arguments

This feature allows you to assert that a Sinon.js spy was called with specific arguments. The code sample demonstrates how to create a spy on a method and then assert that the method was called with a specific argument using Chai's expect syntax.

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

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

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

expect(spy).to.have.been.calledWith('test');

Assert a stub was called a specific number of times

This feature allows you to assert that a Sinon.js stub was called a specific number of times. The code sample demonstrates how to create a stub on a method and then assert that the method was called twice using Chai's expect syntax.

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 stub = sinon.stub(myObj, 'myMethod');
myObj.myMethod();
myObj.myMethod();

expect(stub).to.have.been.calledTwice;

Other packages similar to sinon-chai

Keywords

chai

FAQs

Package last updated on 22 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.