tests: use supertest expect for simple assertions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7027b37 · Browse files · 5 files·+19 added−42 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+19 added−42 removed
- tests:+19 added−42 removed
Provenance
- Commit
dc8acc8- Tree
6280022- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
7027b37
5 files changed+19 added−42 removed
modified:test/app.param.js+4 added-5 removed
27 unmodified lines28 });29 30 request(app)31 .get('/user/tj')32- .end(function(err, res){33- res.text.should.equal('tj');32+ .expect(200, 'tj', function (err) {33+ if (err) return done(err)34 request(app)35 .get('/user/123')36 .expect(404, done);37 });30 unmodified lines68 });69 70 request(app)71 .get('/user/123')72- .end(function(err, res){73- res.text.should.equal('123');74-72+ .expect(200, '123', function (err) {73+ if (err) return done(err)74 request(app)75 .get('/post/123')76 .expect('123', done);77 })289 unmodified linesmodified:test/app.router.js+2 added-2 removed
537 unmodified lines538 });539 540 request(app)541 .get('/user/10')542- .end(function(err, res){543- res.statusCode.should.equal(200);542+ .expect(200, function (err) {543+ if (err) return done(err)544 request(app)545 .get('/user/tj')546 .expect(404, done);547 });542 unmodified linesmodified:test/req.signedCookies.js+1 added-5 removed
26 unmodified lines27282930313233343531323334353626 unmodified lines
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) }); }) })})
modified:test/res.clearCookie.js+4 added-10 removed
11 unmodified lines1213141516171819201617181920215 unmodified lines272829303435363738313233343511 unmodified lines });
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) }) })
describe('.clearCookie(name, options)', function(){5 unmodified lines });
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) }) })})modified:test/res.cookie.js+8 added-20 removed
14 unmodified lines15 });16 17 request(app)18 .get('/')19- .end(function(err, res){20- var val = ['user=' + encodeURIComponent('j:{"name":"tobi"}') + '; Path=/'];21- res.headers['set-cookie'].should.eql(val);22- done();23- })19+ .expect('Set-Cookie', 'user=j%3A%7B%22name%22%3A%22tobi%22%7D; Path=/')20+ .expect(200, done)21 })22 })23 24 describe('.cookie(name, string)', function(){5 unmodified lines30 });31 32 request(app)33 .get('/')37- .end(function(err, res){38- var val = ['name=tobi; Path=/'];39- res.headers['set-cookie'].should.eql(val);40- done();41- })34+ .expect('Set-Cookie', 'name=tobi; Path=/')35+ .expect(200, done)36 })37 38 it('should allow multiple calls', function(done){39 var app = express();25 unmodified lines65 });66 67 request(app)68 .get('/')75- .end(function(err, res){76- var val = ['name=tobi; Path=/; HttpOnly; Secure'];77- res.headers['set-cookie'].should.eql(val);78- done();79- })69+ .expect('Set-Cookie', 'name=tobi; Path=/; HttpOnly; Secure')70+ .expect(200, done)71 })72 73 describe('maxAge', function(){74 it('should set relative expires', function(done){93 unmodified lines168 });169 170 request(app)171 .get('/')181- .end(function(err, res){182- var val = ['name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/'];183- res.headers['set-cookie'].should.eql(val);184- done();185- })172+ .expect('Set-Cookie', 'name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/')173+ .expect(200, done)174 })175 })176 })177 })