smock

0.0.2 • Public • Published

SMock

Simple Mock for javascript. Straight forward and no hussle object mocking.

Smock

$ npm install smock

Example

var Fruit = function(color) {
  this.color = color;
  this.healthy = 'yes';
};
 
Fruit.prototype = {
  cutInPieces: function() {
    return Math.floor(Math.random()*11);
  }
};
 
var redFruit = new Fruit('red');
 
redFruit.color;
// 'red'
redFruit.healthy;
// 'yes'
redFruit.cutInPieces();
// 5
 
var mockedRedFruit = smock(redFruit, { healthy: 'a bit' });
 
mockedRedFruit.healthy;
// 'a bit'
mockedRedFruit.color;
// 'red'
mockedRedFruit.cutInPieces();
// 2
redFruit.healthy;
// 'yes'
// You get the point
var uberChangedFruit = smock(redFruit, {
  color: 'blue',
  cutInPieces: function() {
    return 7;
  }
});
 
uberChangedFruit.color;
// 'blue'
uberChangedFruit.cutInPieces();
// 7
uberChangedFruit.healthy;
// 'yes'

Dependents (0)

Package Sidebar

Install

npm i smock

Weekly Downloads

1

Version

0.0.2

License

none

Last publish

Collaborators

  • elcuervo