Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default server type when using sandbox.useFakeServer() doesn't match documentation #1534

Closed
lsglick opened this issue Aug 17, 2017 · 5 comments · Fixed by #1648
Closed

Default server type when using sandbox.useFakeServer() doesn't match documentation #1534

lsglick opened this issue Aug 17, 2017 · 5 comments · Fixed by #1648

Comments

@lsglick
Copy link

lsglick commented Aug 17, 2017

  • Sinon version : master
  • Environment :
  • Example URL :
  • Other libraries you are using:

What did you expect to happen?
Creating a fake server with sandbox.useFakeServer() should create a fakeServer instance. (According to docs here: http://sinonjs.org/releases/v3.2.0/sandbox/)

What actually happens
It creates a fakeServerWithClock instance.

How to reproduce

var sandbox = sinon.sandbox.create();
sandbox.useFakeServer();
// Verify sandbox.server is a fakeServerWithClock

Workaround is to manually set sandbox.serverPrototype before calling .useFakeServer() since unlike creating server from the sandbox config, there is no way to specify the server prototype when calling the method version of useFakeServer.

This appears to simply be due to setting the wrong prototype here:

serverPrototype: fakeServerWithClock,

So the default || fakeServer is never reached:

var proto = this.serverPrototype || fakeServer;
.

@fatso83
Copy link
Contributor

fatso83 commented Aug 17, 2017

This is basically expanding on #1429. Feel free to have a go at fixing the docs :-)
edit: I was wrong. Read your issue too hastily. I see that you report an actual bug now, as well as reporting on the docs.

Regarding your workaround, it seems overly complicated, why can't you just send in a normal configuration object? This should accomplish the same:

sinon.sandbox.create({
    useFakeTimers: false,
    useFakeServer: true
})

@fatso83 fatso83 added the Bug label Aug 17, 2017
@mantoni
Copy link
Member

mantoni commented Jan 12, 2018

Just ran into this issue as well. I can confirm that this installs a fake server without clock:

sandbox = sinon.createSandbox({
  useFakeServer: true
});

while the following seems to work at first, but installs the fake timers when the first XHR request is made:

sandbox = sinon.createSandbox();
sandbox.useFakeServer();

@mantoni
Copy link
Member

mantoni commented Jan 12, 2018

Actually it's worse. First config version also fails. I'll send a patch in a minute.

mantoni added a commit that referenced this issue Jan 12, 2018
The fakeServerWithClock was used which caused fake timers to be
installed on the first XHR request.

Fixes #1534
mroderick pushed a commit that referenced this issue Jan 13, 2018
The fakeServerWithClock was used which caused fake timers to be
installed on the first XHR request.

Fixes #1534
@mroderick
Copy link
Member

This has been fixed in sinon@4.1.5

@mroderick
Copy link
Member

I made a mistake when building sinon@4.1.5, so it has been deprecated.
All hail sinon@4.1.6

openui5bot pushed a commit to SAP/openui5 that referenced this issue Mar 21, 2018
The sinon release 4.1.3 - which is currently packaged with UI5 as
sinon-4 - has an issue when a fake server is created from a sandbox. The
created server unintentionally fakes timers as well and therefore
doesn't auto-respond.

See sinonjs/sinon#1534 for details.

Sinon release 4.1.6 fixes the issue, this change applies the newest
available release 4.4.6. 

Change-Id: If9207574f1e0b7d253ecb15041b15363086fa541
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
The fakeServerWithClock was used which caused fake timers to be
installed on the first XHR request.

Fixes sinonjs#1534
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants