Socket
Socket
Sign inDemoInstall

sinon-chai

Package Overview
Dependencies
Maintainers
1
Versions
36
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.


Version published
Weekly downloads
698K
decreased by-6.15%
Maintainers
1
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

FAQs

Package last updated on 28 Sep 2017

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