Gobbles up 404 when performing callback

54 views
Skip to first unread message

Simen Bekkhus

unread,
Mar 22, 2013, 9:34:43 AM3/22/13
to sin...@googlegroups.com
Hi!

I've currently wrapped the sinon.fakeserver's respondWith in a helper function. So I now have the possibility to send in urls in an array, what to respond with in an array (JSON), and a callback, which is what triggers the HTTP GETs. And this works fine.

My problem is that if I miss an http-request (which would normally trigger a 404 if not using Sinon), I don't get any feedback on what went wrong, it just gives me an empty object in response to that GET-request. What I do now is to try to make the request without sinon to see what gets requested by the callback (404 in console), then add those URLs and responses to the sinon-function. What I'd like is if sinon would throw a warning of some kind if it intercepts an HTTP-request for which it has not been asked to have a response for.

If this makes no sense at all, say so, and I'll try again.

-Simen

Christian Johansen

unread,
Mar 25, 2013, 3:48:49 AM3/25/13
to sin...@googlegroups.com
Maybe you could provide a little bit more detail, or a very minimal code
skeleton? The fake server will respond with 404 for unknown requests by
default, but it looks like you may have added a handler for all requests
without replicating the 404 behavior?

Christian

Simen Bekkhus

unread,
Mar 25, 2013, 4:26:27 AM3/25/13
to sin...@googlegroups.com
        var paths = [], mockResponses = [], $myButton = $("#myButton");

        mockResponses.push(readFixtures("data1.json"));
        mockResponses.push(readFixtures("data2.json"));

        paths.push("url1");
        paths.push("url2");

        ServerUtils.fakeResponse(paths, mockResponses, {}, function () {
            $myButton.click();
        });



       fakeResponse: function (url, response, options, callback) {
            var statusCode, headers, server, resp, i;

            statusCode = options.statusCode || 200;
            headers = options.headers || {"Content-Type": "application/json"};

            server = sinon.fakeServer.create();

            for (i = 0; i < url.length; i++) {
                server.respondWith(url[i], [statusCode, headers, response[i]]);
            }

            callback();

            resp = server.respond();

            server.restore();
        }

If there is a third request made by clicking that button, I get the silent error I talked about in the opening post. Otherwise it works exactly as intended

-Simen

Simen Bekkhus

unread,
Mar 25, 2013, 6:10:57 AM3/25/13
to sin...@googlegroups.com
Oh, and we're using Sinon 1.6

Simen Bekkhus

unread,
Apr 5, 2013, 3:56:35 AM4/5/13
to sin...@googlegroups.com
Do you have any ideas?

-Simen
Reply all
Reply to author
Forward
0 new messages