diff --git a/tests/javascript.test.js b/tests/javascript.test.js index b1055a7..9f4f394 100644 --- a/tests/javascript.test.js +++ b/tests/javascript.test.js @@ -19,7 +19,7 @@ var interfake; describe('Interfake JavaScript API', function() { beforeEach(function() { - interfake = new Interfake(); + interfake = new Interfake({ debug: true }); }); afterEach(function() { if (interfake) { @@ -206,6 +206,48 @@ describe('Interfake JavaScript API', function() { }); }); + describe('when a body is specified in the request', function () { + beforeEach(function (done) { + interfake.createRoute({ + request: { + url: /match-body/, + method: 'get', + body: { ping: 'pong' } + }, + response: { + code: 200, + body: { + pong: 'ping' + } + } + }); + interfake.listen(3000, done); + }); + + it('should match on the expected body and return the specified response', (done) => { + request({ + url: 'http://localhost:3000/match-body/', + json : true, + body: { ping: 'pong' }, + }, (err, response, body) => { + assert.equal(response.statusCode, 200); + assert.equal(body.pong, 'ping'); + done(); + }); + }); + + it.only('should return a 404 by default if nothing matches', (done) => { + request({ + url: 'http://localhost:3000/match-body/', + json : true, + body: { bing: 'bong' }, + }, (err, response) => { + assert.equal(response.statusCode, 404); + done(); + }); + }); + }); + describe('when the URL is already a regular expression', function () { beforeEach(function (done) { interfake.createRoute({