Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created July 31, 2012 09:50
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 cianclarke/cc106e131f7b9046963b to your computer and use it in GitHub Desktop.
Save cianclarke/cc106e131f7b9046963b to your computer and use it in GitHub Desktop.
FHTesting
/*
Every FeedHenry project should have an associated set of cloud unit tests.
Typically one unit test is created for every public endpoint exported in cloud/main.js,
i.e. every potential $fh.act call.
*/
exports.getList = function(params, callback){
var list = [
{
firstName: 'Henry',
lastName: 'Shefflin'
},
{
firstName: 'Henry',
lastName: 'Kissinger'
}
];
return callback(null, { records: list });
};
/*
Here's what the matching unit test for this would look like
- we'd put this in tests/getList.js. This unit test
uses the 'assert' module, and no testing framework.
Feel free to use the "Mocha" framework, although plain
javascript tests like the following are preferd
*
*/
var main = require('../main'),
assert = require('assert');
main.getList({}, function(err, res){
assert.ok(!err); // make sure no error condition exists
assert.ok(res); // make sure we got some result
var records = res.records;
assert.ok(records); // make sure the records param is set
assert.ok(records.length>0); // make sure we actually got some data back
var aRecord = records[0];
assert.ok(aRecord.firstName); // make sure we have a first and last name
assert.ok(aRecord.lastName);
console.log('getList OK!');
});
/*
We can build a suite of tests in
test/tests.js
*/
var getList = require('./getList'); // this should run the getList test
/*
Lastly, we tell cloud/package.json where to find
our test - note the "scripts" section we've added in
*/
{
"name": "fh-app",
"version": "0.1.0",
"dependencies" : {
"request" : "*"
},
"scripts" : {
"test" : "node test/tests.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment