Permalink
Browse files

skeletal commit

  • Loading branch information...
0 parents commit d27a20e3ecd2fa9395be4d2c65c1b3b44236f469 @vilmibm committed Aug 30, 2012
Showing with 40 additions and 0 deletions.
  1. 0 LICENSE
  2. 0 README.md
  3. +40 −0 lib/faux.js
  4. 0 package.json
  5. 0 tests/test.js
No changes.
No changes.
@@ -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
+};
No changes.
No changes.

0 comments on commit d27a20e

Please sign in to comment.