aboutsummaryrefslogtreecommitdiffstats
path: root/test/support
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-25 16:44:39 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-25 16:44:39 +0200
commit96683161e43fc0101c74f0875d1a2d445afe7e8d (patch)
tree64fca9e7e146a79b433d975de521331b7f21a2ad /test/support
parent536f0c2b8391b95750de370b0f851d8a83d28598 (diff)
downloadjsCalDAV-96683161e43fc0101c74f0875d1a2d445afe7e8d.tar.gz
test/helper add xhr tests
Diffstat (limited to 'test/support')
-rw-r--r--test/support/fake_xhr.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/support/fake_xhr.js b/test/support/fake_xhr.js
new file mode 100644
index 0000000..27e621b
--- /dev/null
+++ b/test/support/fake_xhr.js
@@ -0,0 +1,43 @@
+(function(module) {
+
+ function FakeXhr() {
+ this.openArgs = null;
+ this.sendArgs = null;
+ this.headers = {};
+ this.responseHeaders = {};
+ }
+
+ FakeXhr.prototype = {
+ open: function() {
+ this.openArgs = arguments;
+ },
+
+ getResponseHeader: function(key) {
+ return this.responseHeaders[key];
+ },
+
+ setRequestHeader: function(key, value) {
+ this.headers[key] = value;
+ },
+
+ send: function() {
+ this.sendArgs = arguments;
+ },
+
+ respond: function(data, code) {
+ this.readyState = 4;
+ this.responseHeaders['content-type'] = 'application/json';
+ this.responseText = JSON.stringify(data);
+ this.status = code || 200;
+ this.onreadystatechange();
+ }
+ };
+
+ module.exports = FakeXhr;
+
+}.apply(
+ this,
+ (this.Webcals) ?
+ [Webcals('support/fake_xhr'), Webcals] :
+ [module, require('../../lib/webcals/webcals')]
+));