node-monkeypatch
Slightly easier monkeypatching.
Installation
npm install monkeypatch
Usage
: Function
Monkeypatching a method/function on a target object replaces the method with a newly supplied handler function which will get called instead of the original.
The original method will be returned by monkeypatch()
, and will also be passed as the first argument to the new handler function. See examples.
Examples
Patching a function
var monkeypatch = ; // Monkeypatch Date.now(); var timestamp = Date; // returns a rounded timestamp...
Patching an instance method
var monkeypatch = ; // Monkeypatch Date#getTime(); var date = ;var timestamp = date; // returns a rounded timestamp...
Argument handling
var monkeypatch = ; // Monkeypatch Date#setTime(); var date = ;date; // set to a rounded timestamp...
Unpatching
var monkeypatch = ; // Monkeypatch Date.now(); console; // logs 143942400000 Datenow; console; // logs current time