Socket
Socket
Sign inDemoInstall

007

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

007

Returns a deep copy of an object with all functions converted to spies


Version published
Maintainers
1
Weekly downloads
15
increased by114.29%
Install size
4.99 kB

Weekly downloads

Readme

Source

007

Build Status

Returns a deep copy of an object with all functions converted to spies.

Install

Install with npm:

npm install 007

Example

// we want to test github
var github = require('github');
var doubleOhSeven = require('007');
var mockGithub = doubleOhSeven(github);

mockGithub.pullRequests.getCommits.returns = function () {
  return {
    foo: 'beep'
  };
};

assert(mockGithub.pullRequests.getCommits('lalala').foo === 'beep');
assert(mockGithub.pullRequests.getCommits.callCount === 1);

API

doubleOhSeven()

Takes an object or function as an argument, returns a function or object matching the original, but with mocked out functions.

mockFn.implementation

The implementation of the mock function. Set with =:

Ex:

mockFn.implementation = function (val, cb) {
  return cb(val + 1);
};

The following functions are helpers for implementation; using them will override mockFn.implementation.

mockFn.returns()

The return value of the mock.

Ex:

mockFn.returns('foo');
mockFn(function (arg) {
  console.log(arg); // outputs 'foo'
});
mockFn.callbackArgs()

The callback args to be invoked by the mock.

Ex:

mockFn.callbackArgs(['foo']);
mockFn(function (arg) {
  console.log(arg); // outputs 'foo'
});

License

MIT

Keywords

FAQs

Last updated on 29 Jul 2013

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc