tests: use supertest to perform 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 dc538f6 · Browse files · 3 files·+15 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−26 removed
- tests:+15 added−26 removed
Provenance
- Commit
d0421ac- Tree
adc6ae6- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
dc538f6
3 files changed+15 added−26 removed
modified:test/app.router.js+9 added-15 removed
150 unmodified lines151 });152 153 app.use(function(req, res, next){154 calls.push('after');155- res.end();155+ res.json(calls)156 });157 158 request(app)159 .get('/')160- .end(function(res){161- calls.should.eql(['before', 'GET /', 'after'])162- done();163- })160+ .expect(200, ['before', 'GET /', 'after'], done)161 })162 163 describe('when given a regexp', function(){164 it('should match the pathname only', function(done){722 unmodified lines887 });888 889 app.get('/foo', function(req, res, next){890 calls.push('/foo 2');894- res.end('done');891+ res.json(calls)892 });893 894 request(app)895 .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)897 })898 })899 900 describe('when next("route") is called', function(){74 unmodified lines975 assert(0);976 });977 978 app.use(function(err, req, res, next){985- res.end(err.message);979+ res.json({980+ calls: calls,981+ error: err.message982+ })983 })984 985 request(app)986 .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)988 })989 990 it('should call handler in same route, if exists', function(done){991 var app = express();87 unmodified linesmodified:test/res.cookie.js+2 added-5 removed
106 unmodified linesExpand all10710810911011111111211311411511611711811911611711811912054 unmodified lines106 unmodified linesExpand all var optionsCopy = merge({}, options);
app.use(function(req, res){ res.cookie('name', 'tobi', options) res.end(); res.json(options) });
request(app) .get('/') .end(function(err, res){ options.should.eql(optionsCopy); done(); }) .expect(200, optionsCopy, done) }) })
describe('signed', function(){54 unmodified linesmodified:test/res.locals.js+4 added-6 removed
6 unmodified lines7 it('should be empty by default', function(done){8 var app = express();9 10 app.use(function(req, res){11- Object.keys(res.locals).should.eql([]);12- res.end();11+ res.json(res.locals)12 });13 14 request(app)15 .get('/')17- .expect(200, done);16+ .expect(200, {}, done)17 })18 })19 20 it('should work when mounted', function(done){7 unmodified lines28 next();29 });30 31 app.use(function(req, res){33- res.locals.foo.should.equal('bar');34- res.end();32+ res.json(res.locals)33 });34 35 request(app)36 .get('/')39- .expect(200, done);37+ .expect(200, { foo: 'bar' }, done)38 })39 })