aboutsummaryrefslogtreecommitdiffstats
path: root/test/helper.js
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-07 08:16:54 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-07 08:16:54 -0700
commit0541668eaa804770d51e85037c21887c045642c7 (patch)
tree589945289b3ad98dc447d777d4113d9b536d8900 /test/helper.js
parente45011f8ffff1fd71ea715739390a8d13dda977b (diff)
downloadjsCalDAV-0541668eaa804770d51e85037c21887c045642c7.tar.gz
moved obviously useful mockCallback to testSupport.mock.method
Diffstat (limited to 'test/helper.js')
-rw-r--r--test/helper.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/helper.js b/test/helper.js
index 6157bdb..306a426 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -104,6 +104,45 @@
});
};
+ testSupport.mock = {
+
+ /**
+ * Mocks out a method
+ *
+ * var called = testSupport.mock.method(subject, 'myMethod');
+ *
+ * subject.myMethod('foo', 'bar');
+ *
+ * called.args[0] === 'foo'; // true
+ * called.args[1] === 'bar'; // true
+ *
+ *
+ * @return {Object} reference object.
+ */
+ method: function(obj, method, times) {
+ var calledWith = {};
+ var calls = 0;
+
+ if (typeof(times) === 'undefined') {
+ times = 1;
+ }
+
+ obj[method] = function() {
+ if (calls.length > times) {
+ throw new Error(
+ method + ' called more then ' + times + 'time(s)'
+ );
+ }
+
+ calledWith.args = arguments;
+ calls++;
+ };
+
+ return calledWith;
+ }
+
+ };
+
testSupport.lib = function(lib, callback) {
testSupport.require('/lib/caldav/' + lib, callback);
};