Skip to content

Commit 355a908

Browse files
committed
tests: use assert instead of should
1 parent 0399e39 commit 355a908

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"devDependencies": {
1515
"istanbul": "0.3.5",
1616
"mocha": "~2.1.0",
17-
"should": "~4.1.0",
1817
"supertest": "~0.15.0"
1918
},
2019
"files": [
@@ -26,8 +25,8 @@
2625
"node": ">= 0.8.0"
2726
},
2827
"scripts": {
29-
"test": "mocha --reporter spec --bail --check-leaks --require should test/",
30-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks --require should test/",
31-
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks --require should test/"
28+
"test": "mocha --reporter spec --bail --check-leaks test/",
29+
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
30+
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
3231
}
3332
}

test/test.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
var assert = require('assert');
23
var http = require('http');
34
var path = require('path');
45
var request = require('supertest');
@@ -17,11 +18,11 @@ describe('serveStatic()', function(){
1718
});
1819

1920
it('should require root path', function(){
20-
serveStatic.bind().should.throw(/root path required/);
21+
assert.throws(serveStatic.bind(), /root path required/);
2122
});
2223

2324
it('should require root path to be string', function(){
24-
serveStatic.bind(null, 42).should.throw(/root path.*string/);
25+
assert.throws(serveStatic.bind(null, 42), /root path.*string/);
2526
});
2627

2728
it('should serve static files', function(done){
@@ -195,23 +196,17 @@ describe('serveStatic()', function(){
195196
it('should not include Last-Modifed', function (done) {
196197
request(createServer(fixtures, {'lastModified': false}))
197198
.get('/nums')
198-
.expect(200, '123456789', function (err, res) {
199-
if (err) return done(err)
200-
res.headers.should.not.have.property('last-modified')
201-
done()
202-
})
199+
.expect(shouldNotHaveHeader('Last-Modified'))
200+
.expect(200, '123456789', done)
203201
})
204202
})
205203

206204
describe('when true', function () {
207205
it('should include Last-Modifed', function (done) {
208206
request(createServer(fixtures, {'lastModified': true}))
209207
.get('/nums')
210-
.expect(200, '123456789', function (err, res) {
211-
if (err) return done(err)
212-
res.headers.should.have.property('last-modified')
213-
done()
214-
})
208+
.expect('Last-Modified', /^\w{3}, \d+ \w+ \d+ \d+:\d+:\d+ \w+$/)
209+
.expect(200, '123456789', done)
215210
})
216211
})
217212
})
@@ -288,7 +283,7 @@ describe('serveStatic()', function(){
288283

289284
describe('setHeaders', function () {
290285
it('should reject non-functions', function () {
291-
serveStatic.bind(null, fixtures, {'setHeaders': 3}).should.throw(/setHeaders.*function/)
286+
assert.throws(serveStatic.bind(null, fixtures, {'setHeaders': 3}), /setHeaders.*function/)
292287
})
293288

294289
it('should get called when sending file', function(done){
@@ -309,11 +304,8 @@ describe('serveStatic()', function(){
309304

310305
request(server)
311306
.get('/bogus')
312-
.expect(404, function (err, res) {
313-
if (err) return done(err)
314-
res.headers.should.not.have.property('x-custom')
315-
done()
316-
})
307+
.expect(shouldNotHaveHeader('x-custom'))
308+
.expect(404, done)
317309
})
318310

319311
it('should not get called on redirect', function(done){
@@ -323,11 +315,8 @@ describe('serveStatic()', function(){
323315

324316
request(server)
325317
.get('/users')
326-
.expect(303, function (err, res) {
327-
if (err) return done(err)
328-
res.headers.should.not.have.property('x-custom')
329-
done()
330-
})
318+
.expect(shouldNotHaveHeader('x-custom'))
319+
.expect(303, done)
331320
})
332321
})
333322

@@ -618,3 +607,9 @@ function createServer(dir, opts, fn) {
618607
});
619608
});
620609
}
610+
611+
function shouldNotHaveHeader(header) {
612+
return function (res) {
613+
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)
614+
}
615+
}

0 commit comments

Comments
 (0)