Skip to content
Myr

Route.js

This file

Path

test/Route.js

243 lines · 5.7 KiB · JavaScript

Last changed by

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

History of this file

Take it

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

tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137

line 1why, one step back
1'use strict'

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 2–3why, one step back
2
3var after = require('after');

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 4why, one step back
4var assert = require('assert')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 5–27why, one step back
5var express = require('../')
6 , Route = express.Route7 , methods = require('methods')89describe('Route', function(){10 it('should work without handlers', function(done) {11 var req = { method: 'GET', url: '/' }12 var route = new Route('/foo')13 route.dispatch(req, {}, done)14 })1516 describe('.all', function(){17 it('should add handler', function(done){18 var req = { method: 'GET', url: '/' };19 var route = new Route('/foo');2021 route.all(function(req, res, next) {22 req.called = true;23 next();24 });2526 route.dispatch(req, {}, function (err) {27 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 28why, one step back
28 assert.ok(req.called)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 29–37why, one step back
29 done();
30 });31 })3233 it('should handle VERBS', function(done) {34 var count = 0;35 var route = new Route('/foo');36 var cb = after(methods.length, function (err) {37 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 38why, one step back
38 assert.strictEqual(count, methods.length)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 39–68why, one step back
39 done();
40 });4142 route.all(function(req, res, next) {43 count++;44 next();45 });4647 methods.forEach(function testMethod(method) {48 var req = { method: method, url: '/' };49 route.dispatch(req, {}, cb);50 });51 })5253 it('should stack', function(done) {54 var req = { count: 0, method: 'GET', url: '/' };55 var route = new Route('/foo');5657 route.all(function(req, res, next) {58 req.count++;59 next();60 });6162 route.all(function(req, res, next) {63 req.count++;64 next();65 });6667 route.dispatch(req, {}, function (err) {68 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 69why, one step back
69 assert.strictEqual(req.count, 2)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 70–86why, one step back
70 done();
71 });72 })73 })7475 describe('.VERB', function(){76 it('should support .get', function(done){77 var req = { method: 'GET', url: '/' };78 var route = new Route('');7980 route.get(function(req, res, next) {81 req.called = true;82 next();83 })8485 route.dispatch(req, {}, function (err) {86 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 87why, one step back
87 assert.ok(req.called)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 88–106why, one step back
88 done();
89 });90 })9192 it('should limit to just .VERB', function(done){93 var req = { method: 'POST', url: '/' };94 var route = new Route('');9596 route.get(function(req, res, next) {97 throw new Error('not me!');98 })99100 route.post(function(req, res, next) {101 req.called = true;102 next();103 })104105 route.dispatch(req, {}, function (err) {106 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 107why, one step back
107 assert.ok(req.called)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 108–132why, one step back
108 done();
109 });110 })111112 it('should allow fallthrough', function(done){113 var req = { order: '', method: 'GET', url: '/' };114 var route = new Route('');115116 route.get(function(req, res, next) {117 req.order += 'a';118 next();119 })120121 route.all(function(req, res, next) {122 req.order += 'b';123 next();124 });125126 route.get(function(req, res, next) {127 req.order += 'c';128 next();129 })130131 route.dispatch(req, {}, function (err) {132 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 133why, one step back
133 assert.strictEqual(req.order, 'abc')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 134–158why, one step back
134 done();
135 });136 })137 })138139 describe('errors', function(){140 it('should handle errors via arity 4 functions', function(done){141 var req = { order: '', method: 'GET', url: '/' };142 var route = new Route('');143144 route.all(function(req, res, next){145 next(new Error('foobar'));146 });147148 route.all(function(req, res, next){149 req.order += '0';150 next();151 });152153 route.all(function(err, req, res, next){154 req.order += 'a';155 next(err);156 });157158 route.dispatch(req, {}, function (err) {

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

lines 159–161why, one step back
159 assert.ok(err)
160 assert.strictEqual(err.message, 'foobar')161 assert.strictEqual(req.order, 'a')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 162–184why, one step back
162 done();
163 });164 })165166 it('should handle throw', function(done) {167 var req = { order: '', method: 'GET', url: '/' };168 var route = new Route('');169170 route.all(function(req, res, next){171 throw new Error('foobar');172 });173174 route.all(function(req, res, next){175 req.order += '0';176 next();177 });178179 route.all(function(err, req, res, next){180 req.order += 'a';181 next(err);182 });183184 route.dispatch(req, {}, function (err) {

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

lines 185–187why, one step back
185 assert.ok(err)
186 assert.strictEqual(err.message, 'foobar')187 assert.strictEqual(req.order, 'a')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 188–210why, one step back
188 done();
189 });190 });191192 it('should handle throwing inside error handlers', function(done) {193 var req = { method: 'GET', url: '/' };194 var route = new Route('');195196 route.get(function(req, res, next){197 throw new Error('boom!');198 });199200 route.get(function(err, req, res, next){201 throw new Error('oops');202 });203204 route.get(function(err, req, res, next){205 req.message = err.message;206 next();207 });208209 route.dispatch(req, {}, function (err) {210 if (err) return done(err);

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 211why, one step back
211 assert.strictEqual(req.message, 'oops')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 212–224why, one step back
212 done();
213 });214 });215216 it('should handle throw in .all', function(done) {217 var req = { method: 'GET', url: '/' };218 var route = new Route('');219220 route.all(function(req, res, next){221 throw new Error('boom!');222 });223224 route.dispatch(req, {}, function(err){

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

lines 225–226why, one step back
225 assert.ok(err)
226 assert.strictEqual(err.message, 'boom!')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 227–236why, one step back
227 done();
228 });229 });230231 it('should handle single error handler', function(done) {232 var req = { method: 'GET', url: '/' };233 var route = new Route('');234235 route.all(function(err, req, res, next){236 // this should not execute

tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05

line 237why, one step back
237 throw new Error('should not be called')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 238–243why, one step back
238 });
239240 route.dispatch(req, {}, done);241 });242 })243})