Skip to content

Commit

Permalink
skeletal commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Aug 30, 2012
0 parents commit d27a20e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Empty file added LICENSE
Empty file.
Empty file added README.md
Empty file.
40 changes: 40 additions & 0 deletions lib/faux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var create_nested_mock = function(obj, props) {
var help = function(o, ps) {
if (ps.length === 0) { return }
else {
o[ps[0]] = {};
help(o[ps[0]], ps.slice(1));
}
}
help(obj, props);
return obj;
}

var MockFunction = function(f) {
this.f = (f || noop);
this.called = false;
this.calls = 0;
this.args = [];
var mockf = this;
this.wrapped = function() {
var args = Array.prototype.slice.call(arguments);
mockf.called = true;
mockf.calls += 1;
mockf.args.push(args)
return mockf.f.apply(this, args);
};
var wrapped = this.wrapped;
['called', 'calls', 'args'].forEach(function(x) {
Object.defineProperty(wrapped, x, {
get: function() { return mockf[x] }
});
});
};

var noop = function() {};

module.exports = {
create_nested_mock: create_nested_mock,
MockFunction: MockFunction,
noop: noop
};
Empty file added package.json
Empty file.
Empty file added tests/test.js
Empty file.

0 comments on commit d27a20e

Please sign in to comment.