mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
83 lines
1.6 KiB
JavaScript
83 lines
1.6 KiB
JavaScript
|
|
var express = require('../')
|
|
, request = require('supertest');
|
|
|
|
describe('app', function(){
|
|
it('should emit "mount" when mounted', function(done){
|
|
var blog = express()
|
|
, app = express();
|
|
|
|
blog.on('mount', function(arg){
|
|
arg.should.equal(app);
|
|
done();
|
|
});
|
|
|
|
app.use(blog);
|
|
})
|
|
|
|
describe('.use(app)', function(){
|
|
it('should mount the app', function(done){
|
|
var blog = express()
|
|
, app = express();
|
|
|
|
blog.get('/blog', function(req, res){
|
|
res.end('blog');
|
|
});
|
|
|
|
app.use(blog);
|
|
|
|
request(app)
|
|
.get('/blog')
|
|
.expect('blog', done);
|
|
})
|
|
|
|
it('should support mount-points', function(done){
|
|
var blog = express()
|
|
, forum = express()
|
|
, app = express();
|
|
|
|
blog.get('/', function(req, res){
|
|
res.end('blog');
|
|
});
|
|
|
|
forum.get('/', function(req, res){
|
|
res.end('forum');
|
|
});
|
|
|
|
app.use('/blog', blog);
|
|
app.use('/forum', forum);
|
|
|
|
request(app)
|
|
.get('/blog')
|
|
.expect('blog', function(){
|
|
request(app)
|
|
.get('/forum')
|
|
.expect('forum', done);
|
|
});
|
|
})
|
|
|
|
it('should set the child\'s .parent', function(){
|
|
var blog = express()
|
|
, app = express();
|
|
|
|
app.use('/blog', blog);
|
|
blog.parent.should.equal(app);
|
|
})
|
|
|
|
it('should support dynamic routes', function(done){
|
|
var blog = express()
|
|
, app = express();
|
|
|
|
blog.get('/', function(req, res){
|
|
res.end('success');
|
|
});
|
|
|
|
app.use('/post/:article', blog);
|
|
|
|
request(app)
|
|
.get('/post/once-upon-a-time')
|
|
.expect('success', done);
|
|
})
|
|
})
|
|
})
|