Skip to content
Myr

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

14 files+142 added−165 removed

modified:test/app.engine.js+7 added-6 removed
modified:test/app.js+12 added-12 removed
modified:test/app.locals.js+8 added-6 removed
12var assert = require('assert')3var express = require('../')4var should = require('should')56describe('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 })1819 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
12var assert = require('assert')3var express = require('../')4 , request = require('supertest');56describe('app', function(){
33 unmodified lines
40 })4142 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 })4748 describe('.param(names, fn)', function(){
8 unmodified lines
57 });5859 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 });6364 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 });6869 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 })7980 describe('.param(name, fn)', function(){
8 unmodified lines
89 });9091 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 });9596 request(app)99 .get('/user/123')100 .expect('123', done);97 .get('/user/123')98 .expect(200, 'number:123', done)99 })100101 it('should only call once per request', function(done) {102 var app = express();
262 unmodified lines
modified:test/app.render.js+27 added-27 removed
11 unmodified lines
12 app.locals.user = { name: 'tobi' };1314 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 lines
25 app.locals.user = { name: 'tobi' };2627 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 lines
38 app.locals.user = { name: 'tobi' };3940 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 lines
51 app.set('view engine', 'tmpl');5253 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 lines
7172 app.set('view', View);7374 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 lines
112 app.set('views', path.join(__dirname, 'fixtures'))113114 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 lines
127 app.set('views', path.join(__dirname, 'fixtures'))128129 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 lines
142 app.locals.user = { name: 'tobi' };143144 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 lines
160 app.locals.user = { name: 'tobi' };161162 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 lines
177 app.locals.name = 'tobi';178179 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 lines
218 app.set('view', View);219220 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 lines
244 app.set('view', View);245246 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 lines
274 app.set('view', View);275276 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 lines
297 var user = { name: 'tobi' };298299 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 lines
310 app.locals.user = { name: 'tobi' };311312 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 lines
324 var jane = { name: 'jane' };325326 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 lines
349 app.set('view', View);350351 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 lines
modified:test/app.router.js+2 added-2 removed
49 unmodified lines
50 })5152 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 });5758 it('should re-route when method is altered', function (done) {
1042 unmodified lines
1101 })11021103 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
12var assert = require('assert')3var express = require('../')4 , request = require('supertest');56describe('app', function(){
28 unmodified lines
35 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 });5556 request(app)
5 unmodified lines
modified:test/app.use.js+4 added-4 removed
8 unmodified lines
9 var blog = express()10 , app = express();1112 blog.on('mount', function(arg){13 arg.should.equal(app);13 assert.strictEqual(arg, app)14 done();15 });1617 app.use(blog);
44 unmodified lines
62 var blog = express()63 , app = express();6465 app.use('/blog', blog);66 blog.parent.should.equal(app);66 assert.strictEqual(blog.parent, app)67 })6869 it('should support dynamic routes', function(done){70 var blog = express()
30 unmodified lines
101 res.end('success');102 });103104 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 });112113 app.use('/post/:article', fn1, other, fn2, blog);
427 unmodified lines
modified:test/req.query.js+3 added-1 removed
12var assert = require('assert')3var express = require('../')4 , request = require('supertest');56describe('req', function(){
92 unmodified lines
99 });100101 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 lines
modified:test/req.route.js+6 added-4 removed
6 unmodified lines
7 it('should be the executed Route', function(done){8 var app = express();910 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 });1415 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 });1920 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 lines
3 , request = require('supertest');45describe('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 })1310 app.use(function(req, res){11 req.xhr.should.be.true()12 res.end();13 });1415 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 })2021 it('should case-insensitive', function(done){22 var app = express();2324 app.use(function(req, res){25 req.xhr.should.be.true()26 res.end();27 });2829 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 })2728 it('should return false otherwise', function(done){36 var app = express();3738 app.use(function(req, res){39 req.xhr.should.be.false()40 res.end();41 });4243 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 })3435 it('should return false when not present', function(done){50 var app = express();5152 app.use(function(req, res){53 req.xhr.should.be.false()54 res.end();55 });5657 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
12var express = require('../')3 , request = require('supertest')4 , cookie = require('cookie')4 , cookieParser = require('cookie-parser')5var merge = require('utils-merge');67describe('res', function(){
36 unmodified lines
44 res.end();45 });4647 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 })5354 describe('.cookie(name, string, options)', function(){
20 unmodified lines
75 res.end();76 });7778 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 })8384 it('should set max-age', function(done){85 var app = express();
48 unmodified lines
134 res.cookie('user', { name: 'tobi' }, { signed: true }).end();135 });136137 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 })143144 describe('signed without secret', function(){
33 unmodified lines
modified:test/res.send.js+1 added-1 removed
542 unmodified lines
543 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 });550551 app.use(function (req, res) {
44 unmodified lines
modified:test/utils.js+19 added-18 removed
12var assert = require('assert');3var Buffer = require('safe-buffer').Buffer4var should = require('should')5var utils = require('../lib/utils');67describe('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 })1213 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 })1718 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 })2223 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})2829describe('utils.setCharset(type, charset)', function () {
19 unmodified lines
49});5051describe('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 })5657 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 })6162 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 })6667 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})7273describe('utils.isAbsolute()', function(){
15 unmodified lines
8990describe('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})