Router.js
This file
Path
test/Router.js
79 lines · 2.1 KiB · JavaScript
Last changed by
stylingTJ Holowaychukbefore adoptionb9e32ec
History of this fileTake it
The walk stopped after 200 commits: lines older than 2c14d0c point at it.
clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 1–14why, one step back12var express = require('../')3 , Router = express.Router4 , request = require('./support/http')5 , assert = require('assert');67describe('Router', function(){8 var router, app;910 beforeEach(function(){11 router = new Router;12 app = express();13 })14Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67
line 15why, one step back15 describe('.match(method, url, i)', function(){clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 16–19why, one step back16 it('should match based on index', function(){17 router.route('get', '/foo', function(){});18 router.route('get', '/foob?', function(){});19 router.route('get', '/bar', function(){});stylingTJ Holowaychukbefore adoptionb9e32ec
lines 20–22why, one step back2021 var method = 'GET';22 var url = '/foo?bar=baz';Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67
lines 23–40why, one step back2324 var route = router.match(method, url, 0);25 route.constructor.name.should.equal('Route');26 route.method.should.equal('get');27 route.path.should.equal('/foo');2829 var route = router.match(method, url, 1);30 route.path.should.equal('/foob?');3132 var route = router.match(method, url, 2);33 assert(!route);3435 url = '/bar';36 var route = router.match(method, url);37 route.path.should.equal('/bar');38 })39 })40 fix matchRequest testsTJ Holowaychukbefore adoption32b8613
line 41why, one step back41 describe('.matchRequest(req, i)', function(){Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67
lines 42–45why, one step back42 it('should match based on index', function(){43 router.route('get', '/foo', function(){});44 router.route('get', '/foob?', function(){});45 router.route('get', '/bar', function(){});clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 46–47why, one step back46 var req = { method: 'GET', url: '/foo?bar=baz' };47fix matchRequest testsTJ Holowaychukbefore adoption32b8613
line 48why, one step back48 var route = router.matchRequest(req, 0);clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 49–52why, one step back49 route.constructor.name.should.equal('Route');50 route.method.should.equal('get');51 route.path.should.equal('/foo');52fix matchRequest testsTJ Holowaychukbefore adoption32b8613
line 53why, one step back53 var route = router.matchRequest(req, 1);clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 54–56why, one step back54 req._route_index.should.equal(1);55 route.path.should.equal('/foob?');56fix matchRequest testsTJ Holowaychukbefore adoption32b8613
line 57why, one step back57 var route = router.matchRequest(req, 2);clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 58–60why, one step back58 assert(!route);5960 req.url = '/bar';fix matchRequest testsTJ Holowaychukbefore adoption32b8613
line 61why, one step back61 var route = router.matchRequest(req);clean up weird whitespace in error-pages acceptance testsTJ Holowaychukbefore adoption2c14d0c
lines 62–79why, one step back62 route.path.should.equal('/bar');63 })64 })6566 describe('.middleware', function(){67 it('should dispatch', function(done){68 router.route('get', '/foo', function(req, res){69 res.send('foo');70 });7172 app.use(router.middleware);7374 request(app)75 .get('/foo')76 .expect('foo', done);77 })78 })79})