Skip to content

Commit

Permalink
Use nise.fakeServer as the sandbox serverPrototype
Browse files Browse the repository at this point in the history
The fakeServerWithClock was used which caused fake timers to be
installed on the first XHR request.

Fixes sinonjs#1534
  • Loading branch information
mantoni authored and Franck Romano committed Oct 1, 2019
1 parent 09e26d4 commit 47c2680
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var sinonAssert = require("./assert");
var sinonClock = require("./util/fake_timers");
var fakeServer = require("nise").fakeServer;
var fakeXhr = require("nise").fakeXhr;
var fakeServerWithClock = require("nise").fakeServerWithClock;

var push = [].push;

Expand Down Expand Up @@ -55,7 +54,7 @@ extend(sinonSandbox, {
return this.add(this.clock);
},

serverPrototype: fakeServerWithClock,
serverPrototype: fakeServer,

useFakeServer: function useFakeServer() {
var proto = this.serverPrototype || fakeServer;
Expand Down
22 changes: 21 additions & 1 deletion test/sandbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ describe("sinonSandbox", function () {
assert(fakeServer.isPrototypeOf(server));
});

it("creates server with cock", function () {
it("creates server without clock by default", function () {
var server = this.sandbox.useFakeServer();

refute(fakeServerWithClock.isPrototypeOf(server));
});

it("creates server with clock", function () {
this.sandbox.serverPrototype = fakeServerWithClock;
var server = this.sandbox.useFakeServer();

Expand Down Expand Up @@ -472,6 +478,20 @@ describe("sinonSandbox", function () {
sandbox.restore();
});

it("uses fakeServer as the serverPrototype by default", function () {
var sandbox = sinonSandbox.create();

assert.same(sandbox.serverPrototype, fakeServer);
});

it("uses configured implementation as the serverPrototype", function () {
var sandbox = sinonSandbox.create({
useFakeServer: fakeServerWithClock
});

assert.same(sandbox.serverPrototype, fakeServerWithClock);
});

it("yields clock when faking timers", function () {
var sandbox = sinonSandbox.create(sinonConfig({
injectIntoThis: false,
Expand Down

0 comments on commit 47c2680

Please sign in to comment.