Skip to content
Myr

Router.js

This file

Path

test/Router.js

79 lines · 2.1 KiB · JavaScript

Last changed by

stylingTJ Holowaychukbefore adoptionb9e32ec

History of this file

Take it

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

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

stylingTJ Holowaychukbefore adoptionb9e32ec

lines 20–22why, one step back
20
21 var method = 'GET';22 var url = '/foo?bar=baz';

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

lines 23–40why, one step back
23
24 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 back
41 describe('.matchRequest(req, i)', function(){

Merge pull request #1212 from riadhchtara/Issue944TJ Holowaychukbefore adoptione770b67

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

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

fix matchRequest testsTJ Holowaychukbefore adoption32b8613

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

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

fix matchRequest testsTJ Holowaychukbefore adoption32b8613

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

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

fix matchRequest testsTJ Holowaychukbefore adoption32b8613

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

try npm publishConfigTJ Holowaychukbefore adoption7294806

lines 58–60why, one step back
58 assert(!route);
5960 req.url = '/bar';

fix matchRequest testsTJ Holowaychukbefore adoption32b8613

line 61why, one step back
61 var route = router.matchRequest(req);

try npm publishConfigTJ Holowaychukbefore adoption7294806

lines 62–79why, one step back
62 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})