Skip to content

Commit

Permalink
Wrote some basic tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chakrit Wichian committed Jul 15, 2012
1 parent a997b00 commit 7782da9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
, "version": "0.1.2"
, "description": "Connect middleware that adds a unique id to each request."
, "main": "index.js"
, "scripts": { "test": "test.js" }
, "scripts": { "test": "mocha test.js --reporter nyan --ui bdd" }
, "repository":
{ "type": "git"
, "url": "git://github.com/chakrit/connect-requestid.git" }
Expand Down
39 changes: 38 additions & 1 deletion test.js
@@ -1,4 +1,41 @@

// test.js - Test index.js
var index = require('./index');
// NOTE: must be run usingmocha (http://visionmedia.github.com/mocha/)
(function() {

// check for mocha context
if (!describe || !it) {
console.log("This file is intended to be run using mocha:");
console.log(" http://visionmedia.github.com/mocha/");
return;
}


var index = require('./index')
, assert = require('assert');

describe('index.js', function() {
describe('exports', function() {
it('a middleware function', function() {
assert(typeof index === 'function');
assert(index.length === 3);
});
});
});

describe('middleware function', function() {
it('should generates an id', function(done) {
var obj = { };

index(obj, null, function(e) {
if (!!e) return done(e);

assert('id' in obj);
assert(typeof obj['id'] === 'string');
done();
});
});
});

})();

0 comments on commit 7782da9

Please sign in to comment.