Nerfing Powerful Megalomaniacs
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    smockpublic

    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' 

    Keywords

    none

    install

    npm i smock

    Downloadsweekly downloads

    3

    version

    0.0.2

    license

    none

    last publish

    collaborators

    • avatar