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

gently

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gently

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
753
decreased by-28.29%
Maintainers
0
Weekly downloads
 
Created
Source

Gently

Purpose

A node.js module that helps with mocking and behavior verification.

Features

  • Overwrite and mock individual object functions
  • Verify that all expected calls have been made in the expected order
  • Restore mocked functions to their original behavior

Installation

Via npm:

npm install gently@latest

Example

Make sure your dog is working properly:

function Dog() {}

Dog.prototype.seeCat = function() {
  this.bark('whuf, whuf');
  this.run();
}

Dog.prototype.bark = function(bark) {
  require('sys').puts(bark);
}

var gently = new (require('gently').Gently)
  , assert = require('assert')
  , dog = new Dog();

gently.expect(dog, 'bark', function(bark) {
  assert.equal(bark, 'whuf, whuf');
});
gently.expect(dog, 'run');

dog.seeCat();

You can also easily test event emitters with this, for example a simple sequence of 2 events emitted by fs.WriteStream:

var gently = new (require('gently').Gently)
  , stream = new (require('fs').WriteStream)('my_file.txt');

gently.expect(stream, 'emit', function(event) {
  assert.equal(event, 'open');
});

gently.expect(stream, 'emit', function(event) {
  assert.equal(event, 'drain');
});

API

gently.Gently

new gently.Gently()

Creates a new gently instance. It listens to the process 'exit' event to make sure all expectations have been verified.

gently.expect(obj, method, [[count], mock])

Creates an expectation for an objects method to be called. You can optionally specify the call count you are expecting, as well as mock function that will run instead of the original function.

gently.restore(obj, method)

Restores an object method that has been previously overwritten using gently.expect().

gently.verify()

Verifies that all expectations of this gently instance have been satisfied. If not called manually, this method is called when the process 'exit' event is fired.

License

Gently is licensed under the MIT license.

FAQs

Package last updated on 03 May 2011

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc