Skip to content

Commit

Permalink
tests: use supertest to perform assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 27, 2018
1 parent dc538f6 commit d0421ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
24 changes: 9 additions & 15 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,12 @@ describe('app.router', function(){

app.use(function(req, res, next){
calls.push('after');
res.end();
res.json(calls)
});

request(app)
.get('/')
.end(function(res){
calls.should.eql(['before', 'GET /', 'after'])
done();
})
.expect(200, ['before', 'GET /', 'after'], done)
})

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

app.get('/foo', function(req, res, next){
calls.push('/foo 2');
res.end('done');
res.json(calls)
});

request(app)
.get('/foo')
.expect('done', function(){
calls.should.eql(['/foo/:bar?', '/foo', '/foo 2']);
done();
})
.expect(200, ['/foo/:bar?', '/foo', '/foo 2'], done)
})
})

Expand Down Expand Up @@ -982,15 +976,15 @@ describe('app.router', function(){
});

app.use(function(err, req, res, next){
res.end(err.message);
res.json({
calls: calls,
error: err.message
})
})

request(app)
.get('/foo')
.expect('fail', function(){
calls.should.eql(['/foo/:bar?', '/foo']);
done();
})
.expect(200, { calls: ['/foo/:bar?', '/foo'], error: 'fail' }, done)
})

it('should call handler in same route, if exists', function(done){
Expand Down
7 changes: 2 additions & 5 deletions test/res.cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@ describe('res', function(){

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)
})
})

Expand Down
10 changes: 4 additions & 6 deletions test/res.locals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ describe('res', function(){
var app = express();

app.use(function(req, res){
Object.keys(res.locals).should.eql([]);
res.end();
res.json(res.locals)
});

request(app)
.get('/')
.expect(200, done);
.expect(200, {}, done)
})
})

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

app.use(function(req, res){
res.locals.foo.should.equal('bar');
res.end();
res.json(res.locals)
});

request(app)
.get('/')
.expect(200, done);
.expect(200, { foo: 'bar' }, done)
})
})

0 comments on commit d0421ac

Please sign in to comment.