Skip to content
Myr

Router.js

This file

Path

test/Router.js

78 lines · 2.0 KiB · JavaScript

Last changed by

Issue 944:riadhchtarabefore adoptionf110248

History of this file

Take it

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

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 1–14why, one step back
1
2var 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 })14

Issue 944:riadhchtarabefore adoptionf110248

line 15why, one step back
15 describe('.match(method, url, i)', function(){

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 16–19why, one step back
16 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(){});

Issue 944:riadhchtarabefore adoptionf110248

lines 20–44why, one step back
20 var method = 'GET'
21 , url = '/foo?bar=baz';2223 var route = router.match(method, url, 0);24 route.constructor.name.should.equal('Route');25 route.method.should.equal('get');26 route.path.should.equal('/foo');2728 var route = router.matchRe(method, url, 1);29 route.path.should.equal('/foob?');3031 var route = router.match(method, url, 2);32 assert(!route);3334 req.url = '/bar';35 var route = router.match(method, url);36 route.path.should.equal('/bar');37 })38 })39 40 describe('.matchReq(req, i)', function(){41 it('should match based on index', function(){42 router.route('get', '/foo', function(){});43 router.route('get', '/foob?', function(){});44 router.route('get', '/bar', function(){});

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 45–46why, one step back
45 var req = { method: 'GET', url: '/foo?bar=baz' };
46

Issue 944:riadhchtarabefore adoptionf110248

line 47why, one step back
47 var route = router.matchReq(req, 0);

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 48–51why, one step back
48 route.constructor.name.should.equal('Route');
49 route.method.should.equal('get');50 route.path.should.equal('/foo');51

Issue 944:riadhchtarabefore adoptionf110248

line 52why, one step back
52 var route = router.matchReq(req, 1);

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 53–55why, one step back
53 req._route_index.should.equal(1);
54 route.path.should.equal('/foob?');55

Issue 944:riadhchtarabefore adoptionf110248

line 56why, one step back
56 var route = router.matchReq(req, 2);

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 57–59why, one step back
57 assert(!route);
5859 req.url = '/bar';

Issue 944:riadhchtarabefore adoptionf110248

line 60why, one step back
60 var route = router.matchReq(req);

updated signed cookie testsTJ Holowaychukbefore adoption2079ccb

lines 61–78why, one step back
61 route.path.should.equal('/bar');
62 })63 })6465 describe('.middleware', function(){66 it('should dispatch', function(done){67 router.route('get', '/foo', function(req, res){68 res.send('foo');69 });7071 app.use(router.middleware);7273 request(app)74 .get('/foo')75 .expect('foo', done);76 })77 })78})