mitm-papandreou
Version:
Intercept and mock outgoing network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Useful when testing code that hits remote servers.
16 lines (11 loc) • 313 B
JavaScript
module.exports = Stubs
function Stubs() {}
Stubs.prototype = Object.create(Array.prototype)
Stubs.prototype.stub = function(obj, prop, value) {
this.push([obj, prop, obj[prop]])
obj[prop] = value
}
Stubs.prototype.restore = function() {
var stub
while (stub = this.pop()) stub[0][stub[1]] = stub[2]
}