tests: remove global dependency on should
Before adoption: this commit came in with the history the project adopted, so no landing records it.
fixes #4797
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 215f484 · Browse files · 14 files·+142 added−165 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+142 added−165 removed
- tests:+142 added−165 removed
Provenance
- Commit
bd4fdfe- Tree
2e5fcf1- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
215f484
14 files changed+142 added−165 removed
modified:test/app.engine.js+7 added-6 removed
12345615 unmodified lines2223242525262728293031323233343435363738393 unmodified lines434445464647484950516 unmodified lines585960616162636465666 unmodified lines7374757676777879808182
var assert = require('assert')var express = require('../') , fs = require('fs');var path = require('path')
15 unmodified lines app.locals.user = { name: 'tobi' };
app.render('user.html', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); assert.strictEqual(str, '<p>tobi</p>') done(); }) })
it('should throw when the callback is missing', function(){ var app = express(); (function(){ assert.throws(function () { app.engine('.html', null); }).should.throw('callback function required'); }, /callback function required/) })
it('should work without leading "."', function(done){ var app = express();3 unmodified lines app.locals.user = { name: 'tobi' };
app.render('user.html', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); assert.strictEqual(str, '<p>tobi</p>') done(); }) })
6 unmodified lines app.locals.user = { name: 'tobi' };
app.render('user', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); assert.strictEqual(str, '<p>tobi</p>') done(); }) })
6 unmodified lines app.locals.user = { name: 'tobi' };
app.render('user', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); assert.strictEqual(str, '<p>tobi</p>') done(); }) }) })})modified:test/app.js+12 added-12 removed
30 unmodified lines3132333435363536373839406 unmodified lines4748495051525354515253545556575816 unmodified lines75767778798081798081828384858687888989909192939495969798989910010110210310410510610710710810911030 unmodified lines app.use('/blog', blog); blog.use('/admin', blogAdmin);
assert(!app.parent, 'app.parent'); blog.parent.should.equal(app); blogAdmin.parent.should.equal(blog); assert.strictEqual(blog.parent, app) assert.strictEqual(blogAdmin.parent, blog) })})
describe('app.mountpath', function(){6 unmodified lines app.use('/blog', blog); app.use(fallback); blog.use('/admin', admin);
admin.mountpath.should.equal('/admin'); app.mountpath.should.equal('/'); blog.mountpath.should.equal('/blog'); fallback.mountpath.should.equal('/'); assert.strictEqual(admin.mountpath, '/admin') assert.strictEqual(app.mountpath, '/') assert.strictEqual(blog.mountpath, '/blog') assert.strictEqual(fallback.mountpath, '/') })})
describe('app.router', function(){16 unmodified lines
app.use('/blog', blog); blog.use('/admin', blogAdmin);
app.path().should.equal(''); blog.path().should.equal('/blog'); blogAdmin.path().should.equal('/blog/admin'); assert.strictEqual(app.path(), '') assert.strictEqual(blog.path(), '/blog') assert.strictEqual(blogAdmin.path(), '/blog/admin') })})
describe('in development', function(){ it('should disable "view cache"', function(){ process.env.NODE_ENV = 'development'; var app = express(); app.enabled('view cache').should.be.false() assert.ok(!app.enabled('view cache')) process.env.NODE_ENV = 'test'; })})
describe('in production', function(){ it('should enable "view cache"', function(){ process.env.NODE_ENV = 'production'; var app = express(); app.enabled('view cache').should.be.true() assert.ok(app.enabled('view cache')) process.env.NODE_ENV = 'test'; })})
describe('without NODE_ENV', function(){ it('should default to development', function(){ process.env.NODE_ENV = ''; var app = express(); app.get('env').should.equal('development'); assert.strictEqual(app.get('env'), 'development') process.env.NODE_ENV = 'test'; })})modified:test/app.locals.js+8 added-6 removed
1 2+var assert = require('assert')3 var express = require('../')4+var should = require('should')5 6 describe('app', function(){7 describe('.locals(obj)', function(){8 it('should merge locals', function(){9 var app = express();8- Object.keys(app.locals).should.eql(['settings']);10+ should(Object.keys(app.locals)).eql(['settings'])11 app.locals.user = 'tobi';12 app.locals.age = 2;11- Object.keys(app.locals).should.eql(['settings', 'user', 'age']);12- app.locals.user.should.equal('tobi');13- app.locals.age.should.equal(2);13+ should(Object.keys(app.locals)).eql(['settings', 'user', 'age'])14+ assert.strictEqual(app.locals.user, 'tobi')15+ assert.strictEqual(app.locals.age, 2)16 })17 })18 19 describe('.locals.settings', function(){20 it('should expose app settings', function(){21 var app = express();22 app.set('title', 'House of Manny');23 var obj = app.locals.settings;22- obj.should.have.property('env', 'test');23- obj.should.have.property('title', 'House of Manny');24+ should(obj).have.property('env', 'test')25+ should(obj).have.property('title', 'House of Manny')26 })27 })28 })modified:test/app.param.js+14 added-16 removed
1 2+var assert = require('assert')3 var express = require('../')4 , request = require('supertest');5 6 describe('app', function(){33 unmodified lines40 })41 42 it('should fail if not given fn', function(){43 var app = express();43- app.param.bind(app, ':name', 'bob').should.throw();44+ assert.throws(app.param.bind(app, ':name', 'bob'))45 })46 })47 48 describe('.param(names, fn)', function(){8 unmodified lines57 });58 59 app.get('/post/:id', function(req, res){60 var id = req.params.id;60- id.should.be.a.Number()61- res.send('' + id);61+ res.send((typeof id) + ':' + id)62 });63 64 app.get('/user/:uid', function(req, res){65 var id = req.params.id;66- id.should.be.a.Number()67- res.send('' + id);66+ res.send((typeof id) + ':' + id)67 });68 69 request(app)71- .get('/user/123')72- .expect(200, '123', function (err) {73- if (err) return done(err)74- request(app)75- .get('/post/123')76- .expect('123', done);77- })70+ .get('/user/123')71+ .expect(200, 'number:123', function (err) {72+ if (err) return done(err)73+ request(app)74+ .get('/post/123')75+ .expect('number:123', done)76+ })77 })78 })79 80 describe('.param(name, fn)', function(){8 unmodified lines89 });90 91 app.get('/user/:id', function(req, res){92 var id = req.params.id;94- id.should.be.a.Number()95- res.send('' + id);93+ res.send((typeof id) + ':' + id)94 });95 96 request(app)99- .get('/user/123')100- .expect('123', done);97+ .get('/user/123')98+ .expect(200, 'number:123', done)99 })100 101 it('should only call once per request', function(done) {102 var app = express();262 unmodified linesmodified:test/app.render.js+27 added-27 removed
11 unmodified lines12 app.locals.user = { name: 'tobi' };13 14 app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) {15 if (err) return done(err);16- str.should.equal('<p>tobi</p>');16+ assert.strictEqual(str, '<p>tobi</p>')17 done();18 })19 })20 4 unmodified lines25 app.locals.user = { name: 'tobi' };26 27 app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) {28 if (err) return done(err);29- str.should.equal('<p>tobi</p>');29+ assert.strictEqual(str, '<p>tobi</p>')30 done();31 })32 })33 4 unmodified lines38 app.locals.user = { name: 'tobi' };39 40 app.render('user.tmpl', function (err, str) {41 if (err) return done(err);42- str.should.equal('<p>tobi</p>');42+ assert.strictEqual(str, '<p>tobi</p>')43 done();44 })45 })46 4 unmodified lines51 app.set('view engine', 'tmpl');52 53 app.render('blog/post', function (err, str) {54 if (err) return done(err);55- str.should.equal('<h1>blog post</h1>');55+ assert.strictEqual(str, '<h1>blog post</h1>')56 done();57 })58 })59 11 unmodified lines71 72 app.set('view', View);73 74 app.render('something', function(err, str){75- err.should.be.ok()76- err.message.should.equal('err!');75+ assert.ok(err)76+ assert.strictEqual(err.message, 'err!')77 done();78 })79 })80 31 unmodified lines112 app.set('views', path.join(__dirname, 'fixtures'))113 114 app.render('email.tmpl', function (err, str) {115 if (err) return done(err);116- str.should.equal('<p>This is an email</p>');116+ assert.strictEqual(str, '<p>This is an email</p>')117 done();118 })119 })120 })6 unmodified lines127 app.set('views', path.join(__dirname, 'fixtures'))128 129 app.render('email', function(err, str){130 if (err) return done(err);131- str.should.equal('<p>This is an email</p>');131+ assert.strictEqual(str, '<p>This is an email</p>')132 done();133 })134 })135 })6 unmodified lines142 app.locals.user = { name: 'tobi' };143 144 app.render('user.tmpl', function (err, str) {145 if (err) return done(err);146- str.should.equal('<p>tobi</p>');146+ assert.strictEqual(str, '<p>tobi</p>')147 done();148 })149 })150 9 unmodified lines160 app.locals.user = { name: 'tobi' };161 162 app.render('user.tmpl', function (err, str) {163 if (err) return done(err);164- str.should.equal('<span>tobi</span>');164+ assert.strictEqual(str, '<span>tobi</span>')165 done();166 })167 })168 8 unmodified lines177 app.locals.name = 'tobi';178 179 app.render('name.tmpl', function (err, str) {180 if (err) return done(err);181- str.should.equal('<p>tobi</p>');181+ assert.strictEqual(str, '<p>tobi</p>')182 done();183 })184 })185 32 unmodified lines218 app.set('view', View);219 220 app.render('something', function(err, str){221 if (err) return done(err);222- str.should.equal('abstract engine');222+ assert.strictEqual(str, 'abstract engine')223 done();224 })225 })226 })17 unmodified lines244 app.set('view', View);245 246 app.render('something', function(err, str){247 if (err) return done(err);248- count.should.equal(1);249- str.should.equal('abstract engine');248+ assert.strictEqual(count, 1)249+ assert.strictEqual(str, 'abstract engine')250 app.render('something', function(err, str){251 if (err) return done(err);252- count.should.equal(2);253- str.should.equal('abstract engine');252+ assert.strictEqual(count, 2)253+ assert.strictEqual(str, 'abstract engine')254 done();255 })256 })257 })16 unmodified lines274 app.set('view', View);275 276 app.render('something', function(err, str){277 if (err) return done(err);278- count.should.equal(1);279- str.should.equal('abstract engine');278+ assert.strictEqual(count, 1)279+ assert.strictEqual(str, 'abstract engine')280 app.render('something', function(err, str){281 if (err) return done(err);282- count.should.equal(1);283- str.should.equal('abstract engine');282+ assert.strictEqual(count, 1)283+ assert.strictEqual(str, 'abstract engine')284 done();285 })286 })287 })9 unmodified lines297 var user = { name: 'tobi' };298 299 app.render('user.tmpl', { user: user }, function (err, str) {300 if (err) return done(err);301- str.should.equal('<p>tobi</p>');301+ assert.strictEqual(str, '<p>tobi</p>')302 done();303 })304 })305 4 unmodified lines310 app.locals.user = { name: 'tobi' };311 312 app.render('user.tmpl', {}, function (err, str) {313 if (err) return done(err);314- str.should.equal('<p>tobi</p>');314+ assert.strictEqual(str, '<p>tobi</p>')315 done();316 })317 })318 5 unmodified lines324 var jane = { name: 'jane' };325 326 app.render('user.tmpl', { user: jane }, function (err, str) {327 if (err) return done(err);328- str.should.equal('<p>jane</p>');328+ assert.strictEqual(str, '<p>jane</p>')329 done();330 })331 })332 16 unmodified lines349 app.set('view', View);350 351 app.render('something', {cache: true}, function(err, str){352 if (err) return done(err);353- count.should.equal(1);354- str.should.equal('abstract engine');353+ assert.strictEqual(count, 1)354+ assert.strictEqual(str, 'abstract engine')355 app.render('something', {cache: true}, function(err, str){356 if (err) return done(err);357- count.should.equal(1);358- str.should.equal('abstract engine');357+ assert.strictEqual(count, 1)358+ assert.strictEqual(str, 'abstract engine')359 done();360 })361 })362 })11 unmodified linesmodified:test/app.router.js+2 added-2 removed
49 unmodified lines50 })51 52 it('should reject numbers for app.' + method, function(){53 var app = express();54- app[method].bind(app, '/', 3).should.throw(/Number/);54+ assert.throws(app[method].bind(app, '/', 3), /Number/)55 })56 });57 58 it('should re-route when method is altered', function (done) {1042 unmodified lines1101 })1102 1103 it('should be chainable', function(){1104 var app = express();1105- app.get('/', function(){}).should.equal(app);1105+ assert.strictEqual(app.get('/', function () {}), app)1106 })1107 })modified:test/app.routes.error.js+8 added-6 removed
1+2+var assert = require('assert')3 var express = require('../')4 , request = require('supertest');5 6 describe('app', function(){28 unmodified lines35 a = true;36 next();37 }, function(err, req, res, next){38 b = true;37- err.message.should.equal('fabricated error');39+ assert.strictEqual(err.message, 'fabricated error')40 next(err);41 }, function(err, req, res, next){42 c = true;41- err.message.should.equal('fabricated error');43+ assert.strictEqual(err.message, 'fabricated error')44 next();45 }, function(err, req, res, next){46 d = true;47 next();48 }, function(req, res){47- a.should.be.false()48- b.should.be.true()49- c.should.be.true()50- d.should.be.false()49+ assert.ok(!a)50+ assert.ok(b)51+ assert.ok(c)52+ assert.ok(!d)53 res.send(204);54 });55 56 request(app)5 unmodified linesmodified:test/app.use.js+4 added-4 removed
8 unmodified lines9 var blog = express()10 , app = express();11 12 blog.on('mount', function(arg){13- arg.should.equal(app);13+ assert.strictEqual(arg, app)14 done();15 });16 17 app.use(blog);44 unmodified lines62 var blog = express()63 , app = express();64 65 app.use('/blog', blog);66- blog.parent.should.equal(app);66+ assert.strictEqual(blog.parent, app)67 })68 69 it('should support dynamic routes', function(done){70 var blog = express()30 unmodified lines101 res.end('success');102 });103 104 blog.once('mount', function (parent) {105- parent.should.equal(app);105+ assert.strictEqual(parent, app)106 cb();107 });108 other.once('mount', function (parent) {109- parent.should.equal(app);109+ assert.strictEqual(parent, app)110 cb();111 });112 113 app.use('/post/:article', fn1, other, fn2, blog);427 unmodified linesmodified:test/req.query.js+3 added-1 removed
1 2+var assert = require('assert')3 var express = require('../')4 , request = require('supertest');5 6 describe('req', function(){92 unmodified lines99 });100 101 describe('when "query parser" an unknown value', function () {102 it('should throw', function () {102- createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/);103+ assert.throws(createApp.bind(null, 'bogus'),104+ /unknown value.*query parser/)105 });106 });107 })108 })14 unmodified linesmodified:test/req.route.js+6 added-4 removed
6 unmodified lines7 it('should be the executed Route', function(done){8 var app = express();9 10 app.get('/user/:id/:op?', function(req, res, next){11- req.route.path.should.equal('/user/:id/:op?');11+ res.header('path-1', req.route.path)12 next();13 });14 15 app.get('/user/:id/edit', function(req, res){16- req.route.path.should.equal('/user/:id/edit');16+ res.header('path-2', req.route.path)17 res.end();18 });19 20 request(app)21- .get('/user/12/edit')22- .expect(200, done);21+ .get('/user/12/edit')22+ .expect('path-1', '/user/:id/:op?')23+ .expect('path-2', '/user/:id/edit')24+ .expect(200, done)25 })26 })27 })modified:test/req.xhr.js+22 added-43 removed
2 unmodified lines3 , request = require('supertest');4 5 describe('req', function(){6 describe('.xhr', function(){7- it('should return true when X-Requested-With is xmlhttprequest', function(done){8- var app = express();7+ before(function () {8+ this.app = express()9+ this.app.get('/', function (req, res) {10+ res.send(req.xhr)11+ })12+ })13 10- app.use(function(req, res){11- req.xhr.should.be.true()12- res.end();13- });14-15- request(app)16- .get('/')17- .set('X-Requested-With', 'xmlhttprequest')18- .expect(200, done)14+ it('should return true when X-Requested-With is xmlhttprequest', function(done){15+ request(this.app)16+ .get('/')17+ .set('X-Requested-With', 'xmlhttprequest')18+ .expect(200, 'true', done)19 })20 21 it('should case-insensitive', function(done){22- var app = express();23-24- app.use(function(req, res){25- req.xhr.should.be.true()26- res.end();27- });28-29- request(app)30- .get('/')31- .set('X-Requested-With', 'XMLHttpRequest')32- .expect(200, done)22+ request(this.app)23+ .get('/')24+ .set('X-Requested-With', 'XMLHttpRequest')25+ .expect(200, 'true', done)26 })27 28 it('should return false otherwise', function(done){36- var app = express();37-38- app.use(function(req, res){39- req.xhr.should.be.false()40- res.end();41- });42-43- request(app)44- .get('/')45- .set('X-Requested-With', 'blahblah')46- .expect(200, done)29+ request(this.app)30+ .get('/')31+ .set('X-Requested-With', 'blahblah')32+ .expect(200, 'false', done)33 })34 35 it('should return false when not present', function(done){50- var app = express();51-52- app.use(function(req, res){53- req.xhr.should.be.false()54- res.end();55- });56-57- request(app)58- .get('/')59- .expect(200, done)36+ request(this.app)37+ .get('/')38+ .expect(200, 'false', done)39 })40 })41 })modified:test/res.cookie.js+9 added-19 removed
1 2 var express = require('../')3 , request = require('supertest')4- , cookie = require('cookie')4 , cookieParser = require('cookie-parser')5 var merge = require('utils-merge');6 7 describe('res', function(){36 unmodified lines44 res.end();45 });46 47 request(app)49- .get('/')50- .end(function(err, res){51- var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/'];52- res.headers['set-cookie'].should.eql(val);53- done();54- })48+ .get('/')49+ .expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path=/,gender=%3F; Path=/')50+ .expect(200, done)51 })52 })53 54 describe('.cookie(name, string, options)', function(){20 unmodified lines75 res.end();76 });77 78 request(app)83- .get('/')84- .end(function(err, res){85- res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT');86- done();87- })79+ .get('/')80+ .expect('Set-Cookie', /name=tobi; Max-Age=1; Path=\/; Expires=/)81+ .expect(200, done)82 })83 84 it('should set max-age', function(done){85 var app = express();48 unmodified lines134 res.cookie('user', { name: 'tobi' }, { signed: true }).end();135 });136 137 request(app)144- .get('/')145- .end(function(err, res){146- var val = res.headers['set-cookie'][0];147- val = cookie.parse(val.split('.')[0]);148- val.user.should.equal('s:j:{"name":"tobi"}');149- done();150- })138+ .get('/')139+ .expect('Set-Cookie', 'user=s%3Aj%3A%7B%22name%22%3A%22tobi%22%7D.K20xcwmDS%2BPb1rsD95o5Jm5SqWs1KteqdnynnB7jkTE; Path=/')140+ .expect(200, done)141 })142 })143 144 describe('signed without secret', function(){33 unmodified linesmodified:test/res.send.js+1 added-1 removed
542 unmodified lines543 app.set('etag', function (body, encoding) {544 var chunk = !Buffer.isBuffer(body)545 ? Buffer.from(body, encoding)546 : body;547- chunk.toString().should.equal('hello, world!');547+ assert.strictEqual(chunk.toString(), 'hello, world!')548 return '"custom"';549 });550 551 app.use(function (req, res) {44 unmodified linesmodified:test/utils.js+19 added-18 removed
1 2 var assert = require('assert');3 var Buffer = require('safe-buffer').Buffer4+var should = require('should')5 var utils = require('../lib/utils');6 7 describe('utils.etag(body, encoding)', function(){8 it('should support strings', function(){8- utils.etag('express!')9- .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')9+ assert.strictEqual(utils.etag('express!'),10+ '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')11 })12 13 it('should support utf8 strings', function(){13- utils.etag('express❤', 'utf8')14- .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')14+ assert.strictEqual(utils.etag('express❤', 'utf8'),15+ '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')16 })17 18 it('should support buffer', function(){18- utils.etag(Buffer.from('express!'))19- .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')19+ assert.strictEqual(utils.etag(Buffer.from('express!')),20+ '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')21 })22 23 it('should support empty string', function(){23- utils.etag('')24- .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')24+ assert.strictEqual(utils.etag(''),25+ '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')26 })27 })28 29 describe('utils.setCharset(type, charset)', function () {19 unmodified lines49 });50 51 describe('utils.wetag(body, encoding)', function(){52 it('should support strings', function(){52- utils.wetag('express!')53- .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')53+ assert.strictEqual(utils.wetag('express!'),54+ 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')55 })56 57 it('should support utf8 strings', function(){57- utils.wetag('express❤', 'utf8')58- .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')58+ assert.strictEqual(utils.wetag('express❤', 'utf8'),59+ 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')60 })61 62 it('should support buffer', function(){62- utils.wetag(Buffer.from('express!'))63- .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')63+ assert.strictEqual(utils.wetag(Buffer.from('express!')),64+ 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')65 })66 67 it('should support empty string', function(){67- utils.wetag('')68- .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')68+ assert.strictEqual(utils.wetag(''),69+ 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')70 })71 })72 73 describe('utils.isAbsolute()', function(){15 unmodified lines89 90 describe('utils.flatten(arr)', function(){91 it('should flatten an array', function(){92 var arr = ['one', ['two', ['three', 'four'], 'five']];92- utils.flatten(arr)93- .should.eql(['one', 'two', 'three', 'four', 'five']);93+ should(utils.flatten(arr))94+ .eql(['one', 'two', 'three', 'four', 'five'])95 })96 })