Skip to content

Commit d0421ac

Browse files
committed
tests: use supertest to perform assertions
1 parent dc538f6 commit d0421ac

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

test/app.router.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,12 @@ describe('app.router', function(){
152152

153153
app.use(function(req, res, next){
154154
calls.push('after');
155-
res.end();
155+
res.json(calls)
156156
});
157157

158158
request(app)
159159
.get('/')
160-
.end(function(res){
161-
calls.should.eql(['before', 'GET /', 'after'])
162-
done();
163-
})
160+
.expect(200, ['before', 'GET /', 'after'], done)
164161
})
165162

166163
describe('when given a regexp', function(){
@@ -891,15 +888,12 @@ describe('app.router', function(){
891888

892889
app.get('/foo', function(req, res, next){
893890
calls.push('/foo 2');
894-
res.end('done');
891+
res.json(calls)
895892
});
896893

897894
request(app)
898895
.get('/foo')
899-
.expect('done', function(){
900-
calls.should.eql(['/foo/:bar?', '/foo', '/foo 2']);
901-
done();
902-
})
896+
.expect(200, ['/foo/:bar?', '/foo', '/foo 2'], done)
903897
})
904898
})
905899

@@ -982,15 +976,15 @@ describe('app.router', function(){
982976
});
983977

984978
app.use(function(err, req, res, next){
985-
res.end(err.message);
979+
res.json({
980+
calls: calls,
981+
error: err.message
982+
})
986983
})
987984

988985
request(app)
989986
.get('/foo')
990-
.expect('fail', function(){
991-
calls.should.eql(['/foo/:bar?', '/foo']);
992-
done();
993-
})
987+
.expect(200, { calls: ['/foo/:bar?', '/foo'], error: 'fail' }, done)
994988
})
995989

996990
it('should call handler in same route, if exists', function(done){

test/res.cookie.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,12 @@ describe('res', function(){
108108

109109
app.use(function(req, res){
110110
res.cookie('name', 'tobi', options)
111-
res.end();
111+
res.json(options)
112112
});
113113

114114
request(app)
115115
.get('/')
116-
.end(function(err, res){
117-
options.should.eql(optionsCopy);
118-
done();
119-
})
116+
.expect(200, optionsCopy, done)
120117
})
121118
})
122119

test/res.locals.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ describe('res', function(){
88
var app = express();
99

1010
app.use(function(req, res){
11-
Object.keys(res.locals).should.eql([]);
12-
res.end();
11+
res.json(res.locals)
1312
});
1413

1514
request(app)
1615
.get('/')
17-
.expect(200, done);
16+
.expect(200, {}, done)
1817
})
1918
})
2019

@@ -30,12 +29,11 @@ describe('res', function(){
3029
});
3130

3231
app.use(function(req, res){
33-
res.locals.foo.should.equal('bar');
34-
res.end();
32+
res.json(res.locals)
3533
});
3634

3735
request(app)
3836
.get('/')
39-
.expect(200, done);
37+
.expect(200, { foo: 'bar' }, done)
4038
})
4139
})

0 commit comments

Comments
 (0)