Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/sinon-chai
Advanced tools
TypeScript definitions for 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.
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.
These definitions were written by Kazi Manzur Rashid.
FAQs
TypeScript definitions for sinon-chai
The npm package @types/sinon-chai receives a total of 264,500 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.