mirror of
https://github.com/koajs/examples.git
synced 2026-01-25 14:48:15 +00:00
Merge pull request #88 from bananaappletw/master
Update co-views to fix swig cache problem and add test for blog
This commit is contained in:
commit
1cbbfa7f45
@ -8,7 +8,7 @@ var logger = require('koa-logger');
|
||||
var route = require('koa-route');
|
||||
var parse = require('co-body');
|
||||
var koa = require('koa');
|
||||
var app = koa();
|
||||
var app = module.exports = koa();
|
||||
|
||||
// "database"
|
||||
|
||||
@ -67,5 +67,5 @@ function *create() {
|
||||
|
||||
// listen
|
||||
|
||||
app.listen(3000);
|
||||
console.log('listening on port 3000');
|
||||
if (!module.parent) app.listen(3000);
|
||||
|
||||
|
||||
56
blog/test.js
Normal file
56
blog/test.js
Normal file
@ -0,0 +1,56 @@
|
||||
var app = require('./app');
|
||||
var request = require('supertest').agent(app.listen());
|
||||
|
||||
describe('Blog', function(){
|
||||
describe('GET /',function(){
|
||||
it('should see title "Posts"', function(done){
|
||||
request
|
||||
.get('/')
|
||||
.expect(200, function(err, res){
|
||||
if (err) return done(err);
|
||||
|
||||
res.should.be.html;
|
||||
res.text.should.include('<title>Posts</title>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should see 0 post', function(done){
|
||||
request
|
||||
.get('/')
|
||||
.expect(200, function(err, res){
|
||||
if (err) return done(err);
|
||||
|
||||
res.should.be.html;
|
||||
res.text.should.include('<p>You have <strong>0</strong> posts!</p>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('POST /post/new',function(){
|
||||
it('should create post and redirect to /', function(done){
|
||||
request
|
||||
.post('/post')
|
||||
.send({title: 'Title', body: 'Contents'})
|
||||
.end(function(err, res){
|
||||
if (err) return done(err);
|
||||
|
||||
res.header.location.should.be.equal('/')
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('GET /post/0',function(){
|
||||
it('should see post', function(done){
|
||||
request
|
||||
.get('/post/0')
|
||||
.expect(200, function(err, res){
|
||||
if (err) return done(err);
|
||||
|
||||
res.should.be.html;
|
||||
res.text.should.include('<h1>Title</h1>')
|
||||
res.text.should.include('<p>Contents</p>')
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -9,7 +9,7 @@
|
||||
"co-body": "^1.0.0",
|
||||
"co-busboy": "^1.0.2",
|
||||
"co-fs": "^1.2.0",
|
||||
"co-views": "^0.2.0",
|
||||
"co-views": "^2.1.0",
|
||||
"ejs": "^1.0.0",
|
||||
"koa": "^1.0.0",
|
||||
"koa-basic-auth": "^1.1.1",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user