From be4e53b8fe0b4bec88c9579c88945499c1e598ca Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Fri, 26 May 2017 13:25:52 +0200 Subject: [PATCH 1/2] Add failing tests for sandbox.reset() --- test/sandbox-test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/sandbox-test.js b/test/sandbox-test.js index b3176c9a5..46d1d48d9 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -56,6 +56,22 @@ describe("sinonSandbox", function () { assert.same(sandbox.assert, sinonAssert); }); + it("can be reset without failing when pre-configured to use a fake server", function () { + var sandbox = sinonSandbox.create({useFakeServer: true}); + refute.exception(function () { + sandbox.reset(); + }); + }); + + it("can be reset without failing when configured to use a fake server", function () { + var sandbox = sinonSandbox.create(); + sandbox.useFakeServer(); + refute.exception(function () { + sandbox.reset(); + }); + }); + + describe(".useFakeTimers", function () { beforeEach(function () { this.sandbox = Object.create(sinonSandbox); From 0bf0a798547a3bd608f183a442ac0f384c31c082 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Fri, 26 May 2017 14:02:51 +0200 Subject: [PATCH 2/2] Fix failing sandbox.resetBehavior() --- lib/sinon/util/fake_server.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/sinon/util/fake_server.js b/lib/sinon/util/fake_server.js index 76b9d3fad..100f0ab39 100644 --- a/lib/sinon/util/fake_server.js +++ b/lib/sinon/util/fake_server.js @@ -100,6 +100,9 @@ var fakeServer = { this.xhr = fakeXhr.useFakeXMLHttpRequest(); server.requests = []; server.requestCount = 0; + server.queue = []; + server.responses = []; + this.xhr.onCreate = function (xhrObj) { xhrObj.unsafeHeadersEnabled = function () { @@ -166,10 +169,6 @@ var fakeServer = { handleRequest: function handleRequest(xhr) { if (xhr.async) { - if (!this.queue) { - this.queue = []; - } - push.call(this.queue, xhr); } else { this.processRequest(xhr); @@ -199,10 +198,6 @@ var fakeServer = { return; } - if (!this.responses) { - this.responses = []; - } - if (arguments.length === 1) { body = method; url = method = null;