How to use the sinon.useFakeXMLHttpRequest function in sinon

To help you get started, we’ve selected a few sinon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github videojs / http-streaming / test / test-helpers.js View on Github external
['warn', 'error'].forEach((level) => {
    // you can use .log[level].args to get args
    sinon.stub(videojs.log, level);
    fakeEnvironment.log[level] = videojs.log[level];
    Object.defineProperty(videojs.log[level], 'calls', {
      get() {
        // reset callCount to 0 so they don't have to
        const callCount = this.callCount;

        this.callCount = 0;
        return callCount;
      }
    });
  });
  fakeEnvironment.clock = sinon.useFakeTimers();
  fakeEnvironment.xhr = sinon.useFakeXMLHttpRequest();

  // Sinon 1.10.2 handles abort incorrectly (triggering the error event)
  // Later versions fixed this but broke the ability to set the response
  // to an arbitrary object (in our case, a typed array).
  window.XMLHttpRequest.prototype = Object.create(window.XMLHttpRequest.prototype);
  window.XMLHttpRequest.prototype.abort = function abort() {
    this.response = this.responseText = '';
    this.errorFlag = true;
    this.requestHeaders = {};
    this.responseHeaders = {};

    if (this.readyState > 0 && this.sendFlag) {
      this.readyStateChange(4);
      this.sendFlag = false;
    }
github elastic / kibana / src / legacy / ui / public / test_harness / test_harness.js View on Github external
before(() => {
  // prevent accidental ajax requests
  sinon.useFakeXMLHttpRequest();
});
github TerriaJS / terriajs / test / Models / UrthecastCatalogGroupSpec.js View on Github external
beforeEach(function() {
        terria = new Terria({
            baseUrl: './'
        });

        this.xhr = sinon.useFakeXMLHttpRequest();
        this.xhr.onCreate = function (xhr) {
            requests.push(xhr);
        };
    });
github optimizely / javascript-sdk / packages / optimizely-sdk / lib / index.browser.umdtests.js View on Github external
beforeEach(function() {
        silentLogger = logger.createLogger({
          logLevel: enums.LOG_LEVEL.INFO,
          logToConsole: false,
        });
        sinon.stub(configValidator, 'validate');
        sinon.stub(Optimizely.prototype, 'close');

        xhr = sinon.useFakeXMLHttpRequest();
        global.XMLHttpRequest = xhr;
        requests = [];
        xhr.onCreate = function(req) {
          requests.push(req);
        };

        sinon.spy(console, 'log');
        sinon.spy(console, 'info');
        sinon.spy(console, 'warn');
        sinon.spy(console, 'error');

        sinon.spy(window, 'addEventListener');
      });
github alibaba-fusion / next / test / upload / text-spec.js View on Github external
beforeEach(() => {
        xhr = sinon.useFakeXMLHttpRequest();
        requests = [];
        xhr.onCreate = req => requests.push(req);
    });
github IGNF / geoportal-access-lib / test / end-to-end / spec-functional / test_processisocurve.js View on Github external
beforeEach(function () {
                if (mock) {
                    xhr = sinon.useFakeXMLHttpRequest();
                    requests = [];

                    xhr.onCreate = function (request) {
                        requests.push(request);
                    };
                }
            });
github TTLabs / EvaporateJS / test / retry.spec.js View on Github external
test.before(() => {
  sinon.xhr.supportsCORS = true
  global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
  global.window = {
    localStorage: {},
    console: console
  };
})
github teropa / build-your-own-angularjs / test / compile_spec.js View on Github external
beforeEach(function() {
      xhr = sinon.useFakeXMLHttpRequest();
      requests = [];
      xhr.onCreate = function(req) {
        requests.push(req);
      };
    });
    afterEach(function() {
github scott-w / reps-js / test / app / test_set.js View on Github external
beforeEach(function (done) {
    global.localStorage.clear();

    user.save({
      token: 'test'
    });

    xhr = sinon.useFakeXMLHttpRequest();
    global.window.XMLHttpRequest = xhr;
    xhr.onCreate = function (req) {
      requests.push(req);
    };

    done();
  });