Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhammadghazali/2399002 to your computer and use it in GitHub Desktop.
Save muhammadghazali/2399002 to your computer and use it in GitHub Desktop.
Here's a sample of the boilerplate code that APIeasy eliminates when using APIeasy to test an API
// Get more info about APIEasy: https://github.com/flatiron/api-easy
// This example is originated from the Readme page of APIEasy project page.
// I made this gist just to keep the collection of Vows examples test suite I have to learn.
var request = require('request'),
vows = require('vows'),
assert = require('assert');
vows.describe('your/awesome/api').addBatch({
"When using your awesome api": {
"and your awesome resource": {
"A POST to /awesome": {
topic: function () {
request({
uri: 'http://localhost:8080/awesome',
method: 'POST',
body: JSON.stringify({ test: 'data' }),
headers: {
'Content-Type': 'application/json'
}
}, this.callback)
},
"should respond with 200": function (err, res, body) {
assert.equal(res.statusCode, 200);
},
"should respond with ok": function (err, res, body) {
var result = JSON.parse(body);
assert.equal(result.ok, true);
},
"should respond with x-test-header": function (err, res, body) {
assert.include(res.headers, 'x-test-header');
}
}
}
}
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment