$ npm install smoking
Or add it to your script tag
The idea is to provide simple mocking and stubbing to normal objects, no API, no dependencies.
varthiscolor = color;thishealthy = 'yes';;return MathfloorMathrandom*11;;var redFruit = 'red';redFruitcolor;// 'red'redFruithealthy;// 'yes'redFruitcutInPieces;// 5var stubbedRedFruit = smokingredFruit healthy: 'a bit' ;stubbedRedFruithealthy;// 'a bit'stubbedRedFruitcolor;// 'red'stubbedRedFruitcutInPieces;// 2redFruithealthy;// 'yes'// You get the point
var uberChangedFruit = smokingredFruitcolor: 'blue'return 7;;uberChangedFruitcolor;// 'blue'uberChangedFruitcutInPieces;// 7uberChangedFruithealthy;// 'yes'
You can easily verify the call of methods.
var mockFruit = smokingredFruitexpects cutInPieces: 1 ;mockFruitcutInPieces;smokingmockFruitverify;
Or with a shorthand if it's just one method and needs to be called once
var mockFruit = smokingredFruitexpects'cutInPieces';smokingmockFruitverify;
The prior example will fail with a RangeError because the 'cutInPieces' methods does not get called.
It's a foca's idea :D.