diff --git a/lib/fluent.js b/lib/fluent.js index b17a83f..4176dc1 100644 --- a/lib/fluent.js +++ b/lib/fluent.js @@ -63,6 +63,7 @@ function FluentInterface(server, o) { delay: function(delay) { debug('Replacing delay for', originalPath, JSON.stringify(route.request.query), 'with', delay); route.response.delay = delay; + return this; }, responseHeaders: function (headers) { debug('Replacing response headers for', originalPath, JSON.stringify(route.request.query), 'with', headers); diff --git a/package.json b/package.json index 472af61..45390bb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "interfake", "preferGlobal": true, - "version": "1.7.1", + "version": "1.7.2", "author": "Daniel Hough ", "description": "A simple way to create dummy APIs", "contributors": [ diff --git a/tests/javascript.test.js b/tests/javascript.test.js index 3480855..9397d42 100644 --- a/tests/javascript.test.js +++ b/tests/javascript.test.js @@ -738,7 +738,6 @@ describe('Interfake JavaScript API', function () { describe('#delay()', function() { it('should create one GET endpoint with a particular delay', function (done) { var enoughTimeHasPassed = false; - var _this = this; this.slow(500); interfake.get('/fluent').delay(50); interfake.listen(3000); @@ -746,13 +745,35 @@ describe('Interfake JavaScript API', function () { enoughTimeHasPassed = true; }, 50); - request({ url : 'http://localhost:3000/fluent', json : true }, function (error, response, body) { + request({ url : 'http://localhost:3000/fluent', json : true }, function () { if(!enoughTimeHasPassed) { throw new Error('Response wasn\'t delay for long enough'); } done(); }); }); + + describe('#body()', function() { + it('should create one GET endpoint with a particular delay and body', function (done) { + var enoughTimeHasPassed = false; + this.slow(500); + interfake.get('/fluent').delay(50).body({ + ok: 'yeah' + }); + interfake.listen(3000); + setTimeout(function() { + enoughTimeHasPassed = true; + }, 50); + + request({ url : 'http://localhost:3000/fluent', json : true }, function (error, response, body) { + if(!enoughTimeHasPassed) { + throw new Error('Response wasn\'t delay for long enough'); + } + assert.equal(body.ok, 'yeah'); + done(); + }); + }); + }); }); });