Skip to content

Commit

Permalink
tests: use assert instead of should
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 31, 2014
1 parent 5a84271 commit 4ccc82e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"connect": "3",
"istanbul": "0.3.2",
"mocha": "~1.21.5",
"should": "~4.0.4",
"supertest": "~0.14.0"
},
"files": [
Expand Down
53 changes: 19 additions & 34 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

process.env.NODE_ENV = 'test';

var assert = require('assert')
var connect = require('connect');
var errorHandler = require('..')
var http = require('http')
var request = require('supertest');
var should = require('should');
var util = require('util')

describe('errorHandler()', function () {
Expand Down Expand Up @@ -37,22 +37,14 @@ describe('errorHandler()', function () {
error = {status: 200};
request(server)
.get('/')
.end(function (err, res) {
if (err) throw err;
res.statusCode.should.be.exactly(500);
done();
});
.expect(500, done)
});

it('should pass an error status code to the response object', function (done) {
error = {status: 404};
request(server)
.get('/')
.end(function (err, res) {
if (err) throw err;
res.statusCode.should.be.exactly(404);
done();
});
.expect(404, done)
});
});

Expand All @@ -65,28 +57,25 @@ describe('errorHandler()', function () {
request(server)
.get('/')
.set('Accept', 'text/html')
.end(function (err, res) {
if (err) throw err;
res.headers['content-type'].should.startWith('text/html');
res.text.should.containEql('<title>');
res.text.should.containEql('Error: boom!');
res.text.should.containEql(' &nbsp; &nbsp;at');
done();
});
.expect('Content-Type', /text\/html/)
.expect(/<title>/)
.expect(/Error: boom!/)
.expect(/ &nbsp; &nbsp;at/)
.end(done)
});

it('should return a json response when json is accepted', function (done) {
request(server)
.get('/')
.set('Accept', 'application/json')
.expect('Content-Type', /application\/json/)
.end(function (err, res) {
if (err) throw err;
var errorMessage = JSON.parse(res.text);

res.headers['content-type'].should.startWith('application/json');
errorMessage.should.be.a.Object;
errorMessage.should.have.property('error');
errorMessage.error.should.have.properties(['message', 'stack']);
assert.strictEqual(typeof errorMessage, 'object')
assert.deepEqual(Object.keys(errorMessage).sort(), ['error'])
assert.deepEqual(Object.keys(errorMessage.error).sort(), ['message', 'stack'])

done();
});
Expand All @@ -96,12 +85,8 @@ describe('errorHandler()', function () {
request(server)
.get('/')
.set('Accept', 'bogus')
.end(function (err, res) {
if (err) throw err;
res.headers['content-type'].should.startWith('text/plain');
res.text.should.be.exactly(error.stack.toString());
done();
});
.expect('Content-Type', /text\/plain/)
.expect(500, error.stack.toString(), done)
});
});

Expand Down Expand Up @@ -158,7 +143,7 @@ describe('errorHandler()', function () {
.get('/')
.expect(500, function (err) {
if (err) return done(err)
log.should.startWith('Error: boom!\n at')
assert.equal(log.substr(0, 19), 'Error: boom!\n at')
done()
})
})
Expand All @@ -169,7 +154,7 @@ describe('errorHandler()', function () {
.get('/')
.expect(500, function (err) {
if (err) return done(err)
log.should.equal('boom!')
assert.equal(log, 'boom!')
done()
})
})
Expand All @@ -180,7 +165,7 @@ describe('errorHandler()', function () {
.get('/')
.expect(500, function (err) {
if (err) return done(err)
log.should.equal('{ hop: \'pop\' }')
assert.equal(log, '{ hop: \'pop\' }')
done()
})
})
Expand All @@ -191,7 +176,7 @@ describe('errorHandler()', function () {
.get('/')
.expect(500, function (err) {
if (err) return done(err)
log.should.equal('42')
assert.equal(log, '42')
done()
})
})
Expand All @@ -202,7 +187,7 @@ describe('errorHandler()', function () {
.get('/')
.expect(500, function (err) {
if (err) return done(err)
log.should.equal('boom!')
assert.equal(log, 'boom!')
done()
})
})
Expand Down

0 comments on commit 4ccc82e

Please sign in to comment.