forked from alsotang/node-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.test.js
More file actions
56 lines (48 loc) · 1.34 KB
/
app.test.js
File metadata and controls
56 lines (48 loc) · 1.34 KB
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
var app = require('../app');
var supertest = require('supertest');
var request = supertest(app);
var should = require('should');
describe('test/app.test.js', function () {
it('should return 55 when n is 10', function (done) {
request.get('/fib')
.query({n: 10})
.end(function (err, res) {
res.text.should.equal('55');
done(err);
});
});
var testFib = function (n, expect, done) {
request.get('/fib')
.query({n: n})
.end(function (err, res) {
res.text.should.equal(expect);
done(err);
});
};
it('should return 0 when n === 0', function (done) {
testFib(0, '0', done);
});
it('should equal 1 when n === 1', function (done) {
testFib(1, '1', done);
});
it('should equal 55 when n === 10', function (done) {
testFib(10, '55', done);
});
it('should throw when n > 10', function (done) {
testFib(11, 'n should <= 10', done);
});
it('should throw when n < 0', function (done) {
testFib(-1, 'n should >= 0', done);
});
it('should throw when n isnt Number', function (done) {
testFib('good', 'n should be a Number', done);
});
it('should status 500 when error', function (done) {
request.get('/fib')
.query({n: 100})
.end(function (err, res) {
res.status.should.equal(500);
done(err);
});
});
});