Updated error-pages example with acceptance test.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Robert Sköld · committed by TJ Holowaychuk · parent 9d95645 · Browse files · 2 files·+110 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+110 added−5 removed
- tests:+101 added−0 removed
- other:+9 added−5 removed
Provenance
- Commit
550b910- Tree
c118a3f- Author
Robert Sköld <robert@publicclass.se>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
9d95645
2 files changed+110 added−5 removed
modified:examples/error-pages/app.js+9 added-5 removed
2 unmodified lines3456778910111213131415161718192012 unmodified lines3334353635373839404147 unmodified lines899091929391929495962 unmodified lines * Module dependencies. */
var express = require('../../') , app = express(); , app = module.exports = express() , silent = 'test' == process.env.NODE_ENV;
app.set('views', __dirname + '/views');app.set('view engine', 'jade');
app.use(express.favicon());app.use(express.logger('dev'));
silent || app.use(express.logger('dev'));
// "app.router" positions our routes // above the middleware defined below,// this means that Express will attempt// to match & call routes _before_ continuing12 unmodified lines
app.use(function(req, res, next){ // respond with html page if (req.accepts('html')) { console.log('test'); silent || console.log('test'); res.status(404); res.render('404', { url: req.url }); return; }47 unmodified linesapp.get('/500', function(req, res, next){ next(new Error('keyboard cat!'));});
if (!module.parent) {app.listen(3000);console.log('Express app started on port 3000'); app.listen(3000); silent || console.log('Express started on port 3000');}No newline at end of fileadded:test/acceptance/error-pages.js+101 added
1+var app = require('../../examples/error-pages/app')2+ , request = require('../support/http');3+4+describe('error-pages', function(){5+ describe('GET /', function(){6+ it('should respond with page list', function(done){7+ request(app)8+ .get('/')9+ .expect(/Pages Example/,done)10+ })11+ })12+13+ describe('Accept: text/html',function(){14+ describe('GET /403', function(){15+ it('should respond with 403', function(done){16+ request(app)17+ .get('/403')18+ .expect(403,done)19+ })20+ })21+ describe('GET /404', function(){22+ it('should respond with 404', function(done){23+ request(app)24+ .get('/404')25+ .expect(404,done)26+ })27+ })28+ describe('GET /500', function(){29+ it('should respond with 500', function(done){30+ request(app)31+ .get('/500')32+ .expect(500,done)33+ })34+ })35+ })36+37+38+ describe('Accept: application/json',function(){39+ describe('GET /403', function(){40+ it('should respond with 403', function(done){41+ request(app)42+ .get('/403')43+ .set('Accept','application/json')44+ .expect(403,done)45+ })46+ })47+ describe('GET /404', function(){48+ it('should respond with 404', function(done){49+ request(app)50+ .get('/404')51+ .set('Accept','application/json')52+ .end(function(res){53+ res.should.have.property('statusCode',200)54+ res.should.have.property('body',JSON.stringify({error:'Not found'}))55+ done()56+ })57+ })58+ })59+ describe('GET /500', function(){60+ it('should respond with 500', function(done){61+ request(app)62+ .get('/500')63+ .set('Accept','application/json')64+ .expect(500,done)65+ })66+ })67+ })68+69+70+ describe('Accept: text/plain',function(){71+ describe('GET /403', function(){72+ it('should respond with 403', function(done){73+ request(app)74+ .get('/403')75+ .set('Accept','text/plain')76+ .expect(403,done)77+ })78+ })79+ describe('GET /404', function(){80+ it('should respond with 404', function(done){81+ request(app)82+ .get('/404')83+ .set('Accept','text/plain')84+ .end(function(res){85+ res.should.have.property('statusCode',200)86+ res.should.have.property('body','Not found')87+ done()88+ })89+ })90+ })91+ describe('GET /500', function(){92+ it('should respond with 500', function(done){93+ request(app)94+ .get('/500')95+ .set('Accept','text/plain')96+ .expect(500,done)97+ })98+ })99+ })100+101+})