Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@types/sinon-chai
Advanced tools
@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.
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();
@types/chai provides TypeScript type definitions for the Chai assertion library. While it does not include Sinon.js specific assertions, it is useful for general assertion needs in TypeScript projects.
@types/sinon provides TypeScript type definitions for the Sinon.js library. It allows for creating spies, stubs, and mocks with type safety, but does not include Chai-specific assertions.
chai-as-promised extends Chai with assertions for promises. It is useful for testing asynchronous code and can be used alongside sinon-chai for comprehensive testing.
npm install --save @types/sinon-chai
This package contains type definitions for sinon-chai (https://github.com/domenic/sinon-chai).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sinon-chai/v2.
These definitions were written by Kazi Manzur Rashid.
FAQs
TypeScript definitions for sinon-chai
The npm package @types/sinon-chai receives a total of 78,978 weekly downloads. As such, @types/sinon-chai popularity was classified as popular.
We found that @types/sinon-chai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.