Simplest require mocking
Whats up
Hey there!
This is a simple module mocking tool for your super clever unit testing.
Install
$ npm install --save-dev cuculus
Usage
The simple case:
var cuculus = ; cuculus; // now fs is your object cuculus; // now fs is original
Or:
var cuculus = restorer; restorer = cuculus; // now fs is your object ; // now fs is original
Complete case:
var cuculus = ;// mocking library// feel free to use your favoritevar sinon = ; cuculus; // your tests here // and after all, or, between each testcuculus; // now fs is native and without stubs
API
cuculus.replace(name: string, stub: Any) : Function()
Complete replace the module named name
with stub
. Returns function, that
simple proxy to cuculus.restore(name)
.
cuculus.modify(name: string, replacer: Function(current: Any, onRestore: Function(fn: Function))) : Function()
Modifies current module with replacer
function. If replacer
modifies object, then restore
method will not restore the changes, until you not register the backupers with onRestore
function.
cuculus.restore(name: string[, steps: number])
Restores module name
. If it was modified multiple times, restores to the root, until the steps
limit is not given.
cuculus.drop(name: string)
Drops the cached module from require
. name
should be a module name or a full path to the js file.
License
MIT © Sergey Kamardin