From dc8acc8676bed4aa4afa391ee312baa497d680e2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 5 Mar 2017 00:04:47 -0500 Subject: [PATCH] tests: use supertest expect for simple assertions --- test/app.param.js | 9 ++++----- test/app.router.js | 4 ++-- test/req.signedCookies.js | 6 +----- test/res.clearCookie.js | 14 ++++---------- test/res.cookie.js | 28 ++++++++-------------------- 5 files changed, 19 insertions(+), 42 deletions(-) diff --git a/test/app.param.js b/test/app.param.js index 30885bcdc8..c7a375418c 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -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); @@ -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); diff --git a/test/app.router.js b/test/app.router.js index e838b2e33f..95680f9139 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -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); diff --git a/test/req.signedCookies.js b/test/req.signedCookies.js index 111a0f77df..73880b01b4 100644 --- a/test/req.signedCookies.js +++ b/test/req.signedCookies.js @@ -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) }); }) }) diff --git a/test/res.clearCookie.js b/test/res.clearCookie.js index 92c9d049f0..4822057e92 100644 --- a/test/res.clearCookie.js +++ b/test/res.clearCookie.js @@ -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) }) }) @@ -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) }) }) }) diff --git a/test/res.cookie.js b/test/res.cookie.js index 543af99dcd..4eeaaf094a 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -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) }) }) @@ -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){ @@ -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(){ @@ -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) }) }) })