Skip to content

Commit

Permalink
tests: use supertest expect for simple assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 5, 2017
1 parent 7027b37 commit dc8acc8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 42 deletions.
9 changes: 4 additions & 5 deletions test/app.param.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('app', function(){

request(app)
.get('/user/tj')
.end(function(err, res){
res.text.should.equal('tj');
.expect(200, 'tj', function (err) {
if (err) return done(err)
request(app)
.get('/user/123')
.expect(404, done);
Expand Down Expand Up @@ -69,9 +69,8 @@ describe('app', function(){

request(app)
.get('/user/123')
.end(function(err, res){
res.text.should.equal('123');

.expect(200, '123', function (err) {
if (err) return done(err)
request(app)
.get('/post/123')
.expect('123', done);
Expand Down
4 changes: 2 additions & 2 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ describe('app.router', function(){

request(app)
.get('/user/10')
.end(function(err, res){
res.statusCode.should.equal(200);
.expect(200, function (err) {
if (err) return done(err)
request(app)
.get('/user/tj')
.expect(404, done);
Expand Down
6 changes: 1 addition & 5 deletions test/req.signedCookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Cookie', cookie)
.end(function(err, res){
if (err) return done(err);
res.body.should.eql({ obj: { foo: 'bar' } });
done();
});
.expect(200, { obj: { foo: 'bar' } }, done)
});
})
})
Expand Down
14 changes: 4 additions & 10 deletions test/res.clearCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT';
res.header['set-cookie'].should.eql([val]);
done();
})
.expect('Set-Cookie', 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})
})

Expand All @@ -31,11 +28,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT';
res.header['set-cookie'].should.eql([val]);
done();
})
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})
})
})
28 changes: 8 additions & 20 deletions test/res.cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = ['user=' + encodeURIComponent('j:{"name":"tobi"}') + '; Path=/'];
res.headers['set-cookie'].should.eql(val);
done();
})
.expect('Set-Cookie', 'user=j%3A%7B%22name%22%3A%22tobi%22%7D; Path=/')
.expect(200, done)
})
})

Expand All @@ -34,11 +31,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = ['name=tobi; Path=/'];
res.headers['set-cookie'].should.eql(val);
done();
})
.expect('Set-Cookie', 'name=tobi; Path=/')
.expect(200, done)
})

it('should allow multiple calls', function(done){
Expand Down Expand Up @@ -72,11 +66,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = ['name=tobi; Path=/; HttpOnly; Secure'];
res.headers['set-cookie'].should.eql(val);
done();
})
.expect('Set-Cookie', 'name=tobi; Path=/; HttpOnly; Secure')
.expect(200, done)
})

describe('maxAge', function(){
Expand Down Expand Up @@ -178,11 +169,8 @@ describe('res', function(){

request(app)
.get('/')
.end(function(err, res){
var val = ['name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/'];
res.headers['set-cookie'].should.eql(val);
done();
})
.expect('Set-Cookie', 'name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/')
.expect(200, done)
})
})
})
Expand Down

0 comments on commit dc8acc8

Please sign in to comment.