forked from koajs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
59 lines (54 loc) · 1.47 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
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('negotiation', function() {
describe('json', function() {
it('should respond with json', function(done) {
request
.get('/tobi')
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.expect({ name: 'tobi', species: 'ferret' }, done);
});
});
describe('xml', function() {
it('should respond with xml', function(done) {
request
.get('/tobi')
.set('Accept', 'application/xml')
.expect(200)
.expect('Content-Type', /xml/)
.expect('<name>tobi</name>', done);
});
});
describe('html', function() {
it('should respond with html', function(done) {
request
.get('/tobi')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', /html/)
.expect('<h1>tobi</h1>', done);
});
});
describe('text', function() {
it('should respond with html', function(done) {
request
.get('/tobi')
.set('Accept', 'text/plain')
.expect(200)
.expect('Content-Type', /plain/)
.expect('tobi', done);
});
});
describe('*/*', function() {
it('should give precedence to the first accepted type', function(done) {
request
.get('/tobi')
.set('Accept', '*/*')
.expect(200)
.expect('Content-Type', /json/)
.expect('{"name":"tobi","species":"ferret"}', done);
});
});
});