mocco

1.0.0 • Public • Published

Build Status

Mocco

Mocco is simple mock library. It is very useful for mocking Node.js modules.

Installation

$ npm install mocco

Example

var mocco = require('mocco');

//example class
function Person(){}
Person.prototype.age = function(){
  return 42;
};
var person = new Person();
person.age(); //returns 42

//create Mocco class
var mock = mocco.mock(person);

//we need a special implementation of age() for tests:
mock.hijack(function age(){
  return 22;
});

//or we can do it with name and function
mock.hijack('age', function(){
  return 22;
});

//and call it
person.age(); //new returns 22, not 42

//after tests we restore our method to the original implementation
mock.restore('age');

//or we can restore all methods of Person object
mock.restore();

//or we can restore all methods of all objects
mocco.restore();

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i mocco

Weekly Downloads

1

Version

1.0.0

License

none

Last publish

Collaborators

  • jakubmrozek