From 5019f38e29b4e13968d24f1f511e4c9d3bec1dd1 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 6 Jun 2014 00:38:14 -0400 Subject: [PATCH] tests: add more tests --- test/app.router.js | 5 +++++ test/app.use.js | 5 +++++ test/exports.js | 10 +++++++++- test/res.format.js | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/app.router.js b/test/app.router.js index 50af69be..a1f9a8d3 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -25,6 +25,11 @@ describe('app.router', function(){ [method]('/foo') .expect('head' == method ? '' : method, done); }) + + it('should reject numbers for app.' + method, function(){ + var app = express(); + app[method].bind(app, '/', 3).should.throw(/Number/); + }) }); }) diff --git a/test/app.use.js b/test/app.use.js index 6ebd4eda..9e115e95 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -15,6 +15,11 @@ describe('app', function(){ app.use(blog); }) + it('should reject numbers', function(){ + var app = express(); + app.use.bind(app, 3).should.throw(/Number/); + }) + describe('.use(app)', function(){ it('should mount the app', function(done){ var blog = express() diff --git a/test/exports.js b/test/exports.js index 9a593291..d34a7b1c 100644 --- a/test/exports.js +++ b/test/exports.js @@ -1,7 +1,7 @@ var express = require('../'); var request = require('supertest'); -var assert = require('assert'); +var should = require('should'); describe('exports', function(){ it('should expose Router', function(){ @@ -50,4 +50,12 @@ describe('exports', function(){ .get('/') .expect('bar', done); }) + + it('should throw on old middlewares', function(){ + var error; + try { express.bodyParser; } catch (e) { error = e; } + should(error).have.property('message'); + error.message.should.containEql('middleware'); + error.message.should.containEql('bodyParser'); + }) }) diff --git a/test/res.format.js b/test/res.format.js index 7b846222..260dc329 100644 --- a/test/res.format.js +++ b/test/res.format.js @@ -77,6 +77,24 @@ describe('res', function(){ test(app2); }) + describe('with parameters', function(){ + var app = express(); + + app.use(function(req, res, next){ + res.format({ + 'text/plain; charset=utf-8': function(){ res.send('hey') }, + 'text/html; foo=bar; bar=baz': function(){ res.send('

hey

') }, + 'application/json; q=0.5': function(){ res.send({ message: 'hey' }) } + }); + }); + + app.use(function(err, req, res, next){ + res.send(err.status, 'Supports: ' + err.types.join(', ')); + }); + + test(app); + }) + describe('given .default', function(){ it('should be invoked instead of auto-responding', function(done){ request(app3)