-
Notifications
You must be signed in to change notification settings - Fork 741
/
test.js
64 lines (56 loc) · 1.5 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('should');
const app = require('./app');
const server = app.listen();
const request = require('supertest').agent(server);
describe('Blog', function() {
after(function() {
server.close();
});
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();
});
});
});
});