Permalink
Browse files

added first tests

  • Loading branch information...
tj committed May 23, 2011
1 parent c46c71d commit 88bff01a5eef4046d584651c51bf217aab36f36c
Showing with 40 additions and 1 deletion.
  1. +1 −1 Makefile
  2. +39 −0 test/test.params.js
View
@@ -1,6 +1,6 @@
test:
- @./node_modules/.bin/expresso \
+ @NODE_ENV=test ./node_modules/.bin/expresso \
--require should
.PHONY: test
View
@@ -5,10 +5,49 @@
var express = require('express')
, should = require('should')
+ , assert = require('assert')
, params = require('../');
module.exports = {
'.version': function(){
params.version.should.match(/^\d+\.\d+\.\d+$/);
+ },
+
+ 'arity < 3': function(){
+ var app = express.createServer();
+ params.extend(app);
+
+ app.param('id', Number);
+ app.param('error', function(){ throw new Error('fail') });
+ app.param('lib', function(val){ return false; });
+
+ app.get('/project/:lib', function(req, res, next){
+ res.send('project ' + req.params.lib);
+ });
+
+ app.get('/user/:id', function(req, res, next){
+ var id = req.params.id;
+ res.send('typeof ' + typeof id + ' ' + id);
+ });
+
+ app.get('/error/:error', function(req, res, next){
+
+ });
+
+ assert.response(app,
+ { url: '/project/express' },
+ { status: 404 });
+
+ assert.response(app,
+ { url: '/user/2' },
+ { body: 'typeof number 2' });
+
+ assert.response(app,
+ { url: '/user/tj' },
+ { status: 404 });
+
+ assert.response(app,
+ { url: '/error/hey' },
+ { status: 500 });
}
}

0 comments on commit 88bff01

Please sign in to comment.