Last active
October 3, 2015 04:58
-
-
Save muhammadghazali/2396169 to your computer and use it in GitHub Desktop.
Ghanoz's BDD test suite template in Vows - http://vowsjs.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Scenario: Retrieve unavailable place map details | |
* | |
* Given there is no saved event and place documents | |
* When the consumer request the event location coordinate details | |
* Then the web service should return 404 HTTP status code | |
* And the returned resources should be a JSON response | |
*/ | |
var | |
_ = require('underscore')._, | |
assert = require('assert'), | |
request = require('request'), | |
vows = require('vows'), | |
// local modules | |
config = require('./config/config.js'); | |
var API_BASE_PATH = 'http://fakeapi.com/'; | |
/** | |
* Using nested contexts to mimic nested callbacks: | |
* http://stackoverflow.com/a/6369046 | |
* http://vowsjs.org/#-writing-asynchronous-tests | |
* http://stackoverflow.com/a/7190980 | |
*/ | |
vows.describe('Scenario: Retrieve unavailable place map details') | |
.addBatch({ | |
"\nGiven there is no saved event and place documents": { | |
"\nWhen the consumer request the event location coordinate details": { | |
topic: function () { | |
var insertedDummyPlaceID = '50dc03a31b608b9ca08b553e'; | |
request({ | |
uri: API_BASE_PATH + '/place/' + insertedDummyPlaceID + '/map', | |
method: 'GET' | |
}, this.callback); | |
}, | |
"the web service should return 404 HTTP status code": function (error, response, body) { | |
assert.equal(response.statusCode, 404); | |
}, | |
"and the returned resources should be a JSON response": function (error, response, body) { | |
var result = JSON.parse(body); | |
assert.isNull(error); | |
// the returned resources should be a JSON response | |
assert.strictEqual(response.headers['content-type'] === 'application/json; charset=utf-8', true); | |
// the returned response should contain an array of JSON-based data | |
assert.include(result, 'message'); | |
} | |
} | |
} | |
}) | |
.export(module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vows = require('vows'); | |
var assert = require('assert'); | |
var testSuite = vows.describe('Scenario: Test Fake API Scenario'); | |
testSuite.addBatch({ | |
'GIVEN some context' : { | |
'WHEN I do something' : { | |
topic: function () { return something('value', this.callback); }, | |
// then the do something should return anything | |
'the do something should return anything' : function (error, result) { | |
// assert anything here | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment