Skip to content
Myr

app.use.js

This file

Path

test/app.use.js

167 lines · 3.6 KiB · JavaScript

Last changed by

tests: add more app.use testsDouglas Christopher Wilsonbefore adoptionb4b2efe

History of this file

Take it

The walk stopped after 200 commits: lines older than a02dd20 point at it.

update send to 0.2.0Roman Shtylmanbefore adoptiona02dd20

line 1why, one step back
1

tests: add more app.use testsDouglas Christopher Wilsonbefore adoptionb4b2efe

lines 2–4why, one step back
2var after = require('after');
3var express = require('..');4var request = require('supertest');

update send to 0.2.0Roman Shtylmanbefore adoptiona02dd20

lines 5–18why, one step back
5
6describe('app', function(){7 it('should emit "mount" when mounted', function(done){8 var blog = express()9 , app = express();1011 blog.on('mount', function(arg){12 arg.should.equal(app);13 done();14 });1516 app.use(blog);17 })18

tests: add more testsDouglas Christopher Wilsonbefore adoption5019f38

lines 19–23why, one step back
19 it('should reject numbers', function(){
20 var app = express();21 app.use.bind(app, 3).should.throw(/Number/);22 })23

update send to 0.2.0Roman Shtylmanbefore adoptiona02dd20

lines 24–31why, one step back
24 describe('.use(app)', function(){
25 it('should mount the app', function(done){26 var blog = express()27 , app = express();2829 blog.get('/blog', function(req, res){30 res.end('blog');31 });

remove unnecessary test/support/httpJonathan Ongbefore adoption643397e

line 32why, one step back
32

update send to 0.2.0Roman Shtylmanbefore adoptiona02dd20

lines 33–71why, one step back
33 app.use(blog);
3435 request(app)36 .get('/blog')37 .expect('blog', done);38 })3940 it('should support mount-points', function(done){41 var blog = express()42 , forum = express()43 , app = express();4445 blog.get('/', function(req, res){46 res.end('blog');47 });4849 forum.get('/', function(req, res){50 res.end('forum');51 });5253 app.use('/blog', blog);54 app.use('/forum', forum);5556 request(app)57 .get('/blog')58 .expect('blog', function(){59 request(app)60 .get('/forum')61 .expect('forum', done);62 });63 })6465 it('should set the child\'s .parent', function(){66 var blog = express()67 , app = express();6869 app.use('/blog', blog);70 blog.parent.should.equal(app);71 })

Merge pull request #1964 from blakeembrey/modular-routingRoman Shtylmanbefore adoption4867cf1

lines 72–77why, one step back
72
73 it('should support dynamic routes', function(done){74 var blog = express()75 , app = express();7677 blog.get('/', function(req, res){

Merge pull request #1984 from blakeembrey/params-updateRoman Shtylmanbefore adoptioncc38ccc

line 78why, one step back
78 res.end('success');

Merge pull request #1964 from blakeembrey/modular-routingRoman Shtylmanbefore adoption4867cf1

lines 79–84why, one step back
79 });
8081 app.use('/post/:article', blog);8283 request(app)84 .get('/post/once-upon-a-time')

Merge pull request #1984 from blakeembrey/params-updateRoman Shtylmanbefore adoptioncc38ccc

line 85why, one step back
85 .expect('success', done);

tests: add more app.use testsDouglas Christopher Wilsonbefore adoptionb4b2efe

lines 86–164why, one step back
86 })
87 })8889 describe('.use(middleware)', function(){90 it('should invoke middleware for all requests', function (done) {91 var app = express();92 var cb = after(3, done);9394 app.use(function (req, res) {95 res.send('saw ' + req.method + ' ' + req.url);96 });9798 request(app)99 .get('/')100 .expect(200, 'saw GET /', cb);101102 request(app)103 .options('/')104 .expect(200, 'saw OPTIONS /', cb);105106 request(app)107 .post('/foo')108 .expect(200, 'saw POST /foo', cb);109 })110 })111112 describe('.use(path, middleware)', function(){113 it('should strip path from req.url', function (done) {114 var app = express();115116 app.use('/foo', function (req, res) {117 res.send('saw ' + req.method + ' ' + req.url);118 });119120 request(app)121 .get('/foo/bar')122 .expect(200, 'saw GET /bar', done);123 })124125 it('should invoke middleware for all requests starting with path', function (done) {126 var app = express();127 var cb = after(3, done);128129 app.use('/foo', function (req, res) {130 res.send('saw ' + req.method + ' ' + req.url);131 });132133 request(app)134 .get('/')135 .expect(404, cb);136137 request(app)138 .post('/foo')139 .expect(200, 'saw POST /', cb);140141 request(app)142 .post('/foo/bar')143 .expect(200, 'saw POST /bar', cb);144 })145146 it('should work if path has trailing slash', function (done) {147 var app = express();148 var cb = after(3, done);149150 app.use('/foo/', function (req, res) {151 res.send('saw ' + req.method + ' ' + req.url);152 });153154 request(app)155 .get('/')156 .expect(404, cb);157158 request(app)159 .post('/foo')160 .expect(200, 'saw POST /', cb);161162 request(app)163 .post('/foo/bar')164 .expect(200, 'saw POST /bar', cb);

Merge pull request #1964 from blakeembrey/modular-routingRoman Shtylmanbefore adoption4867cf1

line 165why, one step back
165 })

update send to 0.2.0Roman Shtylmanbefore adoptiona02dd20

lines 166–167why, one step back
166 })
167})