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

chai-spies-next

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-spies-next - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

32

lib/spy.js

@@ -45,5 +45,8 @@ /*!

* const [push, pop] = spy.on(array, ['push', 'pop']);
*
* spy.on(array, 'push', returns => 1)
*
* @param {Object} object
* @param {String|String[]} method name or methods names to spy on
* @param {Function} [fn] mock implementation
* @returns created spy or created spies

@@ -53,6 +56,6 @@ * @api public

Sandbox.prototype.on = function (object, methodName) {
Sandbox.prototype.on = function (object, methodName, fn) {
if (Array.isArray(methodName)) {
return methodName.map(function (name) {
return this.on(object, name);
return this.on(object, name, fn);
}, this);

@@ -74,3 +77,3 @@ }

var method = chai.spy('object.' + methodName, object[methodName]);
var method = chai.spy('object.' + methodName, fn || object[methodName]);
var trackingId = ++spyAmount

@@ -223,19 +226,10 @@

};
proxy.__spy = {
calls: []
, called: false
, name: name
};
/**
* # proxy.reset (function)
*
* Resets spy's state object parameters for instantiation and reuse
* @returns proxy spy object
*/
proxy.reset = function() {
this.__spy = {
calls: []
, called: false
, name: name
};
return this;
}
return proxy.reset();
return proxy;
}

@@ -242,0 +236,0 @@

@@ -5,4 +5,13 @@ {

"description": "Spies for the Chai assertion library.",
"keywords": ["chai", "chai-plugin", "browser", "mocks-and-spies", "testing", "spies", "stubs", "mocks"],
"version": "0.8.0",
"keywords": [
"chai",
"chai-plugin",
"browser",
"mocks-and-spies",
"testing",
"spies",
"stubs",
"mocks"
],
"version": "0.9.0",
"license": "MIT",

@@ -9,0 +18,0 @@ "repository": {

@@ -445,2 +445,19 @@ if (!chai) {

});
it('should allow to overwrite method implementation', function () {
chai.spy.on(object, 'push', function() {
return 5;
});
object.push().should.equal(5);
});
it('should overwrite all methods with the same implementation', function () {
chai.spy.on(object, ['push', 'pop'], function() {
return 5;
});
object.push().should.equal(5);
object.pop().should.equal(5);
})
});

@@ -488,32 +505,2 @@

describe('reset method', function () {
it('should reset spy object values to defaults when called', function() {
var name = 'proxy';
var spy = chai.spy(name);
spy();
spy.should.have.been.called();
spy.__spy.called.should.be.true;
spy.__spy.calls.should.have.length(1);
spy.__spy.name.should.be.equal(name);
spy.reset();
spy.should.not.have.been.called();
spy.__spy.called.should.be.false;
spy.__spy.calls.should.have.length(0);
spy.__spy.name.should.be.equal(name);
});
it('should setup spy with default values when spy is instantiated', function() {
var name = 'proxy';
var spy = chai.spy(name);
spy.should.be.spy;
spy.__spy.called.should.be.false;
spy.__spy.calls.should.have.length(0);
spy.__spy.name.should.be.equal(name);
});
});
describe('spy restore', function () {

@@ -520,0 +507,0 @@ var array;

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