Skip to content

Commit

Permalink
Merge pull request #1428 from fatso83/failing-sandbox-reset
Browse files Browse the repository at this point in the history
Fix failing reset() on sandbox with unused fake server
  • Loading branch information
fatso83 committed May 26, 2017
2 parents fe049aa + 0bf0a79 commit c81d76b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/sinon/util/fake_server.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -199,10 +198,6 @@ var fakeServer = {
return;
}

if (!this.responses) {
this.responses = [];
}

if (arguments.length === 1) {
body = method;
url = method = null;
Expand Down
16 changes: 16 additions & 0 deletions test/sandbox-test.js
Expand Up @@ -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);
Expand Down

0 comments on commit c81d76b

Please sign in to comment.