
Security News
Federal Audit Finds NIST Wasted Funds With No Plan to Clear NVD Backlog
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.
A tiny spy library for Node.js.
spy([callback])Use the spy function to create a new spy.
var spy = require('spyny');
var mySpy = spy();
You can also provide a callback to be ran when the spy is called. It will recieve all arguments that are passed to the spy.
var mySpy = spy(function(name) {
return 'Hello, ' + name + '!';
});
console.log(mySpy('Dave'));
// Hello, Dave!
calledCheck if a spy was called.
mySpy();
console.log(mySpy.called);
// true
callCountCheck how many times a spy was called.
mySpy();
mySpy();
console.log(mySpy.callCount);
// 2
callWith()Alternative way of setting the spy callback.
mySpy.callWith(function(name) {
return 'Yo, ' + name + '!';
});
console.log(mySpy('Dave'));
// Yo, Dave!
getCall()Get the details of a specific call.
mySpy('yo!');
console.log(mySpy.getCall(0));
// {
// args: ['yo!']
// }
reset()Flush all previous call data.
mySpy();
mySpy.reset();
console.log(mySpy.called);
// false
returns()Assign a return value for the spy.
mySpy.returns('Howdy!');
console.log(mySpy());
// Howdy!
===
spy.on(obj, method, [callback])Spy on an objects method. Contains all properties and methods of spy().
var Dave = {
greet: function(person) {
return 'Hello, ' + person + '!';
}
};
spy.on(Dave, 'greet').returns('Howdy');
console.log(Dave.greet('Gabe'));
// Howdy
You can also pass in a callback to be invoked.
spy.on(Dave, 'greet', function(person) {
return 'Howdy, ' + person + '.';
});
console.log(Dave.greet('Gabe'));
// Howdy, Gabe.
restore()Restore a method to its previous state.
spy.on(Dave, 'greet');
Dave.greet.restore();
console.log(Dave.greet('Gabe'));
// Hello, Gabe!
passthrough()When called it instructs the spy to use the original method as the callback.
spy.on(Dave, 'greet').passthrough();
console.log(Dave.greet('Gabe'));
// Hello, Gabe!
console.log(Dave.greet.getCall(0));
// {
// args: ['Gabe']
// }
===
spy.sandbox()Create a sandbox object to contain all of your spies. Useful for mass cleanups.
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
spy([callback])Creates a spy contained within the sandbox. Contains the same properties and methods as a normal spy.
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
var mySpy = spy();
mySpy();
console.log(mySpy.called);
// true
spy.on(obj, method, [callback])Creates a spy for an object's method within the sandbox. Contains the same properties and methods as a normal spy.on()
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
spy.on(Dave, 'greet').passthrough();
console.log(Dave.greet.called);
// false
reset()Resets all spies within the sandbox.
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
var spy1 = spy();
var spy2 = spy();
spy1();
spy2();
spy2();
sandbox.reset();
console.log(spy1.called);
// false
console.log(spy2.callCount);
// 0
restore()Restores all spies created via spy.on() to previous state.
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
spy.on(Dave, 'greet', function() {
return 'asdf!';
});
sandbox.restore();
console.log(Dave.greet('Gabe'));
// Hello, Gabe!
flush()Clear all cached spies from the sandbox. Note: this does not restore/reset spies, this simply clears them all from the sandbox cache.
var sandbox = require('spyny').sandbox();
var spy = sandbox.spy;
spy.on(Dave, 'greet', function() {
return 'hi';
});
sandbox.flush();
sandbox.restore(); // `Dave.greet` is still a spy
ISC
FAQs
Tiny spy library
We found that spyny demonstrated a not healthy version release cadence and project activity because the last version was released 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
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.