0.0.2 • Published 9 years ago

property-replacer v0.0.2

Weekly downloads
1
License
GPLv2
Repository
-
Last release
9 years ago

property-replacer

Write javascript unit tests where you can safely replace object properties and undo the replacement on teardown. Inspired by perl Test::Resub and python redef

Build Status

Installation

npm install property-replacer

Usage

Replacer.replace(object, key, anything); --> replace any key on an object with anything. Replacer.reset(); --> put all replaced properties back to normal.

var Replacer = require('property-replacer');
// some constructor
var Cat = function() {
};
Cat.prototype.meow = function() { return 'meow'; };

Replacer.replace(Cat.prototype, 'meow', function() { return 'bark!'; });
var cat = new Cat();
var meow = cat.meow();
// returns bark!

Replacer.reset();
meow = cat.meow();
// returns meow