Skip to content

Commit

Permalink
WIP Written tests so far but not tried to implement, for #51
Browse files Browse the repository at this point in the history
  • Loading branch information
basicallydan committed Aug 10, 2019
1 parent c487c32 commit 3fe9b30
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/javascript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 3fe9b30

Please sign in to comment.