Permalink
Browse files

Fixed path matching test

  • Loading branch information...
1 parent f9da31f commit 470cfc22223b6b4ad9f15da3516faaf9aa8920f6 @tj tj committed Oct 12, 2011
Showing with 53 additions and 60 deletions.
  1. +53 −60 test/connect.test.js
View
@@ -83,66 +83,59 @@ module.exports = {
{ body: 'hello', headers: { 'X-Bar': 'baz' }});
},
- // 'test path matching': function(){
- // var n = 0
- // , app = connect.createServer();
- //
- // app.use('/hello/world', function(req, res, next){
- // switch (++n) {
- // case 1:
- // case 2:
- // req.url.should.equal('/');
- // break;
- // case 3:
- // req.originalUrl.should.equal('/hello/world/and/more/segments');
- // req.url.should.equal('/and/more/segments');
- // break;
- // case 4:
- // req.url.should.equal('/images/foo.png?with=query&string');
- // break;
- // }
- //
- // res.end('hello world');
- // });
- //
- // app.use('/hello', function(req, res, next){
- // res.end('hello');
- // });
- //
- // var foo = connect(function(req, res, next){
- // res.end(foo.route);
- // });
- //
- // app.use('/foo', foo);
- //
- // assert.response(app,
- // { url: '/foo' },
- // { body: '/foo' });
- //
- // assert.response(app,
- // { url: '/hello' },
- // { body: 'hello' });
- //
- // assert.response(app,
- // { url: '/hello/' },
- // { body: 'hello' });
- //
- // assert.response(app,
- // { url: '/hello/world' },
- // { body: 'hello world' });
- //
- // assert.response(app,
- // { url: '/hello/world/' },
- // { body: 'hello world' });
- //
- // assert.response(app,
- // { url: '/hello/world/and/more/segments' },
- // { body: 'hello world' });
- //
- // assert.response(app,
- // { url: '/hello/world/images/foo.png?with=query&string' },
- // { body: 'hello world' });
- // },
+ 'test path matching': function(){
+ var n = 0
+ , app = connect.createServer();
+
+ app.use('/hello/world', function(req, res, next){
+ if (~req.url.indexOf('/images')) {
+ req.url.should.equal('/images/foo.png?with=query&string');
+ } else if (~req.url.indexOf('/and')) {
+ req.originalUrl.should.equal('/hello/world/and/more/segments');
+ req.url.should.equal('/and/more/segments');
+ }
+
+ res.end('hello world');
+ });
+
+ app.use('/hello', function(req, res, next){
+ res.end('hello');
+ });
+
+ var foo = connect(function(req, res, next){
+ res.end(foo.route);
+ });
+
+ app.use('/foo', foo);
+
+ assert.response(app,
+ { url: '/foo' },
+ { body: '/foo' });
+
+ assert.response(app,
+ { url: '/hello' },
+ { body: 'hello' });
+
+ assert.response(app,
+ { url: '/hello/' },
+ { body: 'hello' });
+
+ assert.response(app,
+ { url: '/hello/world' },
+ { body: 'hello world' });
+
+ assert.response(app,
+ { url: '/hello/world/' },
+ { body: 'hello world' });
+
+ assert.response(app,
+ { url: '/hello/world/and/more/segments' },
+ { body: 'hello world' });
+
+ assert.response(app,
+ { url: '/hello/world/images/foo.png?with=query&string' },
+ { body: 'hello world' });
+ },
'test unmatched path': function(){
var app = connect.createServer();

0 comments on commit 470cfc2

Please sign in to comment.