aboutsummaryrefslogtreecommitdiffstats
path: root/test/support/fake_xhr.js
blob: 3f6cea00b2facd111d7b9781c4282acb0d099708 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(module) {
  console.log('I HAZ LOADED');

  function FakeXhr() {
    this.openArgs = null;
    this.sendArgs = null;
    this.headers = {};
    this.responseHeaders = {};
    this.constructorArgs = arguments;

    FakeXhr.instances.push(this);
  }

  FakeXhr.instances = [];

  FakeXhr.prototype = {
    open: function() {
      this.openArgs = Array.prototype.slice.call(arguments);
    },

    getResponseHeader: function(key) {
      return this.responseHeaders[key];
    },

    setRequestHeader: function(key, value) {
      this.headers[key] = value;
    },

    send: function() {
      this.sendArgs = Array.prototype.slice.call(arguments);
    },

    respond: function(data, code, headers) {
      if (headers) {
        this.responseHeaders = headers;
      } else {
        this.responseHeaders['content-type'] = 'text/xml';
      }

      this.readyState = 4;
      this.responseText = data;
      this.status = code || 200;
      this.onreadystatechange();
    }
  };

  console.log('EXPORTS ME', FakeXhr);
  module.exports = FakeXhr;

}.apply(
  this,
  (this.Caldav) ?
    [Caldav('support/fake_xhr'), Caldav] :
    [module, require('../../lib/caldav/caldav')]
));