Skip to content
Myr

Router.js

This file

Path

test/Router.js

78 lines · 2.0 KiB · JavaScript

Last changed by

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

History of this file

Take it

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

ocdTJ Holowaychukbefore adoption5ea78cf

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

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

ocdTJ Holowaychukbefore adoption5ea78cf

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(){});

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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.match(method, url, 1);29 route.path.should.equal('/foob?');3031 var route = router.match(method, url, 2);32 assert(!route);3334 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(){});

ocdTJ Holowaychukbefore adoption5ea78cf

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

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

ocdTJ Holowaychukbefore adoption5ea78cf

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

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

ocdTJ Holowaychukbefore adoption5ea78cf

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

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

ocdTJ Holowaychukbefore adoption5ea78cf

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

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

ocdTJ Holowaychukbefore adoption5ea78cf

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})