javascript - Why doesn't my sinon fake server return anything? -


i'm trying setup fake sinon server testing requests. in code below, callback function never gets called. test errors out error: timeout of 500ms exceeded. ensure done() callback being called in test. why callback function not called immediately?

var request = require('request'); var sinon = require('sinon');  describe('job gets data', function(){      var server;      beforeeach(function(){         server = sinon.fakeserver.create();     });      aftereach(function(){         server.restore();     });      context('when there request /something', function(){          it('will throw error if response format invalid', sinon.test(function(done){              server.respondwith('get', '/something', [200, { "content-type": "application/json" }, '{invalid: "data"}']);             request.get('/something', function (err, response, body) {                 console.log(response);                 console.log(body);                 done();             });         }));      }); 

you need call server.respond have of requests complete. i found gist gives example.

this relevant code.

server.respondwith("get", "/something",                    [200, { "content-type": "application/json" },                     '{ "stuff": "is", "awesome": "in here" }']);  var callbacks = [sinon.spy(), sinon.spy()];  jquery.ajax({   url: "/something",   success: callbacks[0] });  jquery.ajax({   url: "/other",   success: callbacks[1] });  console.log(server.requests); // logs requests far server.respond(); // process requests far 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -