aboutsummaryrefslogblamecommitdiffstats
path: root/test/support/fake_xhr.js
blob: 3f6cea00b2facd111d7b9781c4282acb0d099708 (plain) (tree)
1
2
3
4
5
6
7
8
9
                   
                              





                              
                                     

                                 

   

                         

                       
                                                            










                                            
                                                            

      






                                                          
                          
                               




                                
                                     



                           


                                                
   
(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')]
));