Fake Server responses only on certain requests defined with server.respondWith(url, response)

418 views
Skip to first unread message

Burin

unread,
Apr 29, 2011, 11:43:06 AM4/29/11
to Sinon.JS
By default, a 404 is returned when a fakeServer is created and no
respondWith()'s are defined, and according to the API, you can
override this by setting server.respondWith(response), which works
great.

Is there a way to defer back to "real xhr" for requests that dont have
an appropriate response set up?

I've been using sinon in my unit tests, but since it's been so useful,
I'm considering using it in development to mock web service responses
so I can work while the service is down, I'm offline, etc.

All of my requests to the service are /srv/something.json, but I'd
like to be able to only fake certain endpoints and allow those not
defined with an appropriate respondWith matcher to go ahead and make
the real call.

Christian Johansen

unread,
May 2, 2011, 3:13:16 AM5/2/11
to sin...@googlegroups.com
Hi,

Currently, you can not fall back to the real XMLHttpRequest without a bit of tinkering. I am currently putting some shine on the 1.1 release, where features to enable Sinon as a mockup tool are on the table, so I will see what I can do.

Christian
--
MVH
Christian

Christian Johansen

unread,
May 6, 2011, 2:21:23 AM5/6/11
to sin...@googlegroups.com

Hi,

I am sorry, but this feature did not make it into 1.1.0. It's actually a bit complicated, because xhr/activexobject need to determine if they should handle a request or not and use the non-fake version correctly on each call.

If anyone wants to give it a shot I'd be happy to pull. If not, I will look at it later, but I am currently prioritizing another project.

Christian

--
MVH
Christian

Tino Butz

unread,
Apr 11, 2013, 9:31:18 AM4/11/13
to sin...@googlegroups.com, chri...@cjohansen.no
Hi,

Any news on this? This feature would really help.

Tino

Tino Butz

unread,
Apr 11, 2013, 9:37:03 AM4/11/13
to sin...@googlegroups.com, chri...@cjohansen.no
Hi,

Sorry, just found it. It is available since 1.3 - Thanks!:

FakeXMLHttpRequest.useFilters (default false)

When set to true, Sinon will check added filters if certain requests should be "unfaked".

FakeXMLHttpRequest.addFilter(fn)

Reply all
Reply to author
Forward
0 new messages