tests: remove usage of should

This commit is contained in:
Douglas Christopher Wilson 2022-02-21 19:54:52 -05:00
parent 9967ffbdc2
commit bc5ca05509
6 changed files with 46 additions and 47 deletions

View File

@ -76,7 +76,6 @@
"nyc": "15.1.0",
"pbkdf2-password": "1.2.1",
"resolve-path": "1.4.0",
"should": "13.2.3",
"supertest": "6.2.2",
"vhost": "~3.0.2"
},

View File

@ -1,7 +1,7 @@
'use strict'
var after = require('after');
var should = require('should');
var assert = require('assert')
var express = require('../')
, Route = express.Route
, methods = require('methods')
@ -25,7 +25,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
should(req.called).be.ok()
assert.ok(req.called)
done();
});
})
@ -35,7 +35,7 @@ describe('Route', function(){
var route = new Route('/foo');
var cb = after(methods.length, function (err) {
if (err) return done(err);
count.should.equal(methods.length);
assert.strictEqual(count, methods.length)
done();
});
@ -66,7 +66,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
req.count.should.equal(2);
assert.strictEqual(req.count, 2)
done();
});
})
@ -84,7 +84,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
should(req.called).be.ok()
assert.ok(req.called)
done();
});
})
@ -104,7 +104,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
should(req.called).be.true()
assert.ok(req.called)
done();
});
})
@ -130,7 +130,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
req.order.should.equal('abc');
assert.strictEqual(req.order, 'abc')
done();
});
})
@ -156,9 +156,9 @@ describe('Route', function(){
});
route.dispatch(req, {}, function (err) {
should(err).be.ok()
should(err.message).equal('foobar');
req.order.should.equal('a');
assert.ok(err)
assert.strictEqual(err.message, 'foobar')
assert.strictEqual(req.order, 'a')
done();
});
})
@ -182,9 +182,9 @@ describe('Route', function(){
});
route.dispatch(req, {}, function (err) {
should(err).be.ok()
should(err.message).equal('foobar');
req.order.should.equal('a');
assert.ok(err)
assert.strictEqual(err.message, 'foobar')
assert.strictEqual(req.order, 'a')
done();
});
});
@ -208,7 +208,7 @@ describe('Route', function(){
route.dispatch(req, {}, function (err) {
if (err) return done(err);
should(req.message).equal('oops');
assert.strictEqual(req.message, 'oops')
done();
});
});
@ -222,8 +222,8 @@ describe('Route', function(){
});
route.dispatch(req, {}, function(err){
should(err).be.ok()
err.message.should.equal('boom!');
assert.ok(err)
assert.strictEqual(err.message, 'boom!')
done();
});
});
@ -234,7 +234,7 @@ describe('Route', function(){
route.all(function(err, req, res, next){
// this should not execute
true.should.be.false()
throw new Error('should not be called')
});
route.dispatch(req, {}, done);

View File

@ -3,11 +3,10 @@
var assert = require('assert')
var express = require('../');
var request = require('supertest');
var should = require('should');
describe('exports', function(){
it('should expose Router', function(){
express.Router.should.be.a.Function()
assert.strictEqual(typeof express.Router, 'function')
})
it('should expose json middleware', function () {
@ -36,20 +35,23 @@ describe('exports', function(){
})
it('should expose the application prototype', function(){
express.application.set.should.be.a.Function()
assert.strictEqual(typeof express.application, 'object')
assert.strictEqual(typeof express.application.set, 'function')
})
it('should expose the request prototype', function(){
express.request.accepts.should.be.a.Function()
assert.strictEqual(typeof express.request, 'object')
assert.strictEqual(typeof express.request.accepts, 'function')
})
it('should expose the response prototype', function(){
express.response.send.should.be.a.Function()
assert.strictEqual(typeof express.response, 'object')
assert.strictEqual(typeof express.response.send, 'function')
})
it('should permit modifying the .application prototype', function(){
express.application.foo = function(){ return 'bar'; };
express().foo().should.equal('bar');
assert.strictEqual(express().foo(), 'bar')
})
it('should permit modifying the .request prototype', function(done){
@ -79,10 +81,7 @@ describe('exports', function(){
})
it('should throw on old middlewares', function(){
var error;
try { express.bodyParser; } catch (e) { error = e; }
should(error).have.property('message');
error.message.should.containEql('middleware');
error.message.should.containEql('bodyParser');
assert.throws(function () { express.bodyParser() }, /Error:.*middleware.*bodyParser/)
assert.throws(function () { express.limit() }, /Error:.*middleware.*limit/)
})
})

View File

@ -1,2 +0,0 @@
--require should
--slow 20

View File

@ -7,7 +7,6 @@ var express = require('../')
, assert = require('assert');
var onFinished = require('on-finished');
var path = require('path');
var should = require('should');
var fixtures = path.join(__dirname, 'fixtures');
var utils = require('./support/utils');
@ -359,15 +358,13 @@ describe('res', function(){
app.use(function (req, res) {
res.sendFile(path.resolve(fixtures, 'does-not-exist'), function (err) {
should(err).be.ok()
err.status.should.equal(404);
res.send('got it');
res.send(err ? 'got ' + err.status + ' error' : 'no error')
});
});
request(app)
.get('/')
.expect(200, 'got it', done);
.get('/')
.expect(200, 'got 404 error', done)
})
})
@ -539,7 +536,7 @@ describe('res', function(){
app.use(function(req, res){
res.sendfile('test/fixtures/user.html', function(err){
assert(!res.headersSent);
req.socket.listeners('error').should.have.length(1); // node's original handler
assert.strictEqual(req.socket.listeners('error').length, 1) // node's original handler
done();
});
@ -783,12 +780,12 @@ describe('res', function(){
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(404);
calls.should.equal(1);
done();
});
.get('/')
.expect(404, function (err) {
if (err) return done(err)
assert.strictEqual(calls, 1)
done()
})
})
describe('with non-GET', function(){

View File

@ -2,7 +2,6 @@
var assert = require('assert');
var Buffer = require('safe-buffer').Buffer
var should = require('should')
var utils = require('../lib/utils');
describe('utils.etag(body, encoding)', function(){
@ -91,7 +90,14 @@ describe('utils.isAbsolute()', function(){
describe('utils.flatten(arr)', function(){
it('should flatten an array', function(){
var arr = ['one', ['two', ['three', 'four'], 'five']];
should(utils.flatten(arr))
.eql(['one', 'two', 'three', 'four', 'five'])
var flat = utils.flatten(arr)
assert.strictEqual(flat.length, 5)
assert.strictEqual(flat[0], 'one')
assert.strictEqual(flat[1], 'two')
assert.strictEqual(flat[2], 'three')
assert.strictEqual(flat[3], 'four')
assert.strictEqual(flat[4], 'five')
assert.ok(flat.every(function (v) { return typeof v === 'string' }))
})
})