Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
originalXHR.prototype.open = function (method, url) {
let mock = tractor.getMatchingMock(method, url);
if (!mock) {
let message = `Unexpected "${method}" request to "${url}".`;
/* eslint-disable no-console */
console.error(message);
/* eslint-enable no-console */
}
if (!mock || mock && mock.passThrough) {
return originalOpen.apply(this, arguments);
}
let real = this;
let fake = new FakeXMLHttpRequest();
Object.setPrototypeOf(real, FakeXMLHttpRequest.prototype);
real.send = function () {
copyEvents(real, fake);
FakeXMLHttpRequest.prototype.send.apply(this, arguments);
fake.send.apply(fake, arguments);
FakeXMLHttpRequest.prototype.respond.call(this, mock.status, mock.headers, mock.body);
fake.respond.apply(fake, arguments);
};
copyEvents(real, fake);
FakeXMLHttpRequest.prototype.open.apply(this, arguments);
fake.open.apply(fake, arguments);
};