Skip to content

Commit c81d76b

Browse files
authored
Merge pull request #1428 from fatso83/failing-sandbox-reset
Fix failing reset() on sandbox with unused fake server
2 parents fe049aa + 0bf0a79 commit c81d76b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/sinon/util/fake_server.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ var fakeServer = {
100100
this.xhr = fakeXhr.useFakeXMLHttpRequest();
101101
server.requests = [];
102102
server.requestCount = 0;
103+
server.queue = [];
104+
server.responses = [];
105+
103106

104107
this.xhr.onCreate = function (xhrObj) {
105108
xhrObj.unsafeHeadersEnabled = function () {
@@ -166,10 +169,6 @@ var fakeServer = {
166169

167170
handleRequest: function handleRequest(xhr) {
168171
if (xhr.async) {
169-
if (!this.queue) {
170-
this.queue = [];
171-
}
172-
173172
push.call(this.queue, xhr);
174173
} else {
175174
this.processRequest(xhr);
@@ -199,10 +198,6 @@ var fakeServer = {
199198
return;
200199
}
201200

202-
if (!this.responses) {
203-
this.responses = [];
204-
}
205-
206201
if (arguments.length === 1) {
207202
body = method;
208203
url = method = null;

test/sandbox-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ describe("sinonSandbox", function () {
5656
assert.same(sandbox.assert, sinonAssert);
5757
});
5858

59+
it("can be reset without failing when pre-configured to use a fake server", function () {
60+
var sandbox = sinonSandbox.create({useFakeServer: true});
61+
refute.exception(function () {
62+
sandbox.reset();
63+
});
64+
});
65+
66+
it("can be reset without failing when configured to use a fake server", function () {
67+
var sandbox = sinonSandbox.create();
68+
sandbox.useFakeServer();
69+
refute.exception(function () {
70+
sandbox.reset();
71+
});
72+
});
73+
74+
5975
describe(".useFakeTimers", function () {
6076
beforeEach(function () {
6177
this.sandbox = Object.create(sinonSandbox);

0 commit comments

Comments
 (0)