diff --git a/test/app.engine.js b/test/app.engine.js index b198292fa0..0d54c90d56 100644 --- a/test/app.engine.js +++ b/test/app.engine.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , fs = require('fs'); var path = require('path') @@ -22,16 +23,16 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') 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){ @@ -43,7 +44,7 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -58,7 +59,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -73,7 +74,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) diff --git a/test/app.js b/test/app.js index e52365c36b..d0756795d3 100644 --- a/test/app.js +++ b/test/app.js @@ -32,8 +32,8 @@ describe('app.parent', function(){ 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) }) }) @@ -48,10 +48,10 @@ describe('app.mountpath', function(){ 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, '/') }) }) @@ -76,9 +76,9 @@ describe('app.path()', function(){ 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') }) }) @@ -86,7 +86,7 @@ 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'; }) }) @@ -95,7 +95,7 @@ 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'; }) }) @@ -104,7 +104,7 @@ 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'; }) }) diff --git a/test/app.locals.js b/test/app.locals.js index d8bfb5a987..0b14ac9070 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -1,16 +1,18 @@ +var assert = require('assert') var express = require('../') +var should = require('should') describe('app', function(){ describe('.locals(obj)', function(){ it('should merge locals', function(){ var app = express(); - Object.keys(app.locals).should.eql(['settings']); + should(Object.keys(app.locals)).eql(['settings']) app.locals.user = 'tobi'; app.locals.age = 2; - Object.keys(app.locals).should.eql(['settings', 'user', 'age']); - app.locals.user.should.equal('tobi'); - app.locals.age.should.equal(2); + should(Object.keys(app.locals)).eql(['settings', 'user', 'age']) + assert.strictEqual(app.locals.user, 'tobi') + assert.strictEqual(app.locals.age, 2) }) }) @@ -19,8 +21,8 @@ describe('app', function(){ var app = express(); app.set('title', 'House of Manny'); var obj = app.locals.settings; - obj.should.have.property('env', 'test'); - obj.should.have.property('title', 'House of Manny'); + should(obj).have.property('env', 'test') + should(obj).have.property('title', 'House of Manny') }) }) }) diff --git a/test/app.param.js b/test/app.param.js index 577b00710b..7dbe3ffb61 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -40,7 +41,7 @@ describe('app', function(){ it('should fail if not given fn', function(){ var app = express(); - app.param.bind(app, ':name', 'bob').should.throw(); + assert.throws(app.param.bind(app, ':name', 'bob')) }) }) @@ -57,24 +58,22 @@ describe('app', function(){ app.get('/post/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); app.get('/user/:uid', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect(200, '123', function (err) { - if (err) return done(err) - request(app) - .get('/post/123') - .expect('123', done); - }) + .get('/user/123') + .expect(200, 'number:123', function (err) { + if (err) return done(err) + request(app) + .get('/post/123') + .expect('number:123', done) + }) }) }) @@ -91,13 +90,12 @@ describe('app', function(){ app.get('/user/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect('123', done); + .get('/user/123') + .expect(200, 'number:123', done) }) it('should only call once per request', function(done) { diff --git a/test/app.render.js b/test/app.render.js index 54f6c2ca82..d0b367189b 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -13,7 +13,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -26,7 +26,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -39,7 +39,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -52,7 +52,7 @@ describe('app', function(){ app.render('blog/post', function (err, str) { if (err) return done(err); - str.should.equal('

blog post

'); + assert.strictEqual(str, '

blog post

') done(); }) }) @@ -72,8 +72,8 @@ describe('app', function(){ app.set('view', View); app.render('something', function(err, str){ - err.should.be.ok() - err.message.should.equal('err!'); + assert.ok(err) + assert.strictEqual(err.message, 'err!') done(); }) }) @@ -113,7 +113,7 @@ describe('app', function(){ app.render('email.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -128,7 +128,7 @@ describe('app', function(){ app.render('email', function(err, str){ if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -143,7 +143,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -161,7 +161,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('tobi'); + assert.strictEqual(str, 'tobi') done(); }) }) @@ -178,7 +178,7 @@ describe('app', function(){ app.render('name.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -219,7 +219,7 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - str.should.equal('abstract engine'); + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -245,12 +245,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(2); - str.should.equal('abstract engine'); + assert.strictEqual(count, 2) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -275,12 +275,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -298,7 +298,7 @@ describe('app', function(){ app.render('user.tmpl', { user: user }, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -311,7 +311,7 @@ describe('app', function(){ app.render('user.tmpl', {}, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -325,7 +325,7 @@ describe('app', function(){ app.render('user.tmpl', { user: jane }, function (err, str) { if (err) return done(err); - str.should.equal('

jane

'); + assert.strictEqual(str, '

jane

') done(); }) }) @@ -350,12 +350,12 @@ describe('app', function(){ app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) diff --git a/test/app.router.js b/test/app.router.js index a4fe57cc2b..6edb93d6ea 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -51,7 +51,7 @@ describe('app.router', function(){ it('should reject numbers for app.' + method, function(){ var app = express(); - app[method].bind(app, '/', 3).should.throw(/Number/); + assert.throws(app[method].bind(app, '/', 3), /Number/) }) }); @@ -1102,6 +1102,6 @@ describe('app.router', function(){ it('should be chainable', function(){ var app = express(); - app.get('/', function(){}).should.equal(app); + assert.strictEqual(app.get('/', function () {}), app) }) }) diff --git a/test/app.routes.error.js b/test/app.routes.error.js index cbbc23ef57..b1f95d0d6e 100644 --- a/test/app.routes.error.js +++ b/test/app.routes.error.js @@ -1,3 +1,5 @@ + +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -34,20 +36,20 @@ describe('app', function(){ next(); }, function(err, req, res, next){ b = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(err); }, function(err, req, res, next){ c = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(); }, function(err, req, res, next){ d = true; next(); }, function(req, res){ - a.should.be.false() - b.should.be.true() - c.should.be.true() - d.should.be.false() + assert.ok(!a) + assert.ok(b) + assert.ok(c) + assert.ok(!d) res.send(204); }); diff --git a/test/app.use.js b/test/app.use.js index 347937fbb3..7987405a8b 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -10,7 +10,7 @@ describe('app', function(){ , app = express(); blog.on('mount', function(arg){ - arg.should.equal(app); + assert.strictEqual(arg, app) done(); }); @@ -63,7 +63,7 @@ describe('app', function(){ , app = express(); app.use('/blog', blog); - blog.parent.should.equal(app); + assert.strictEqual(blog.parent, app) }) it('should support dynamic routes', function(done){ @@ -102,11 +102,11 @@ describe('app', function(){ }); blog.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); other.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); diff --git a/test/req.query.js b/test/req.query.js index 0e810b8ef9..f3e8df8a18 100644 --- a/test/req.query.js +++ b/test/req.query.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -99,7 +100,8 @@ describe('req', function(){ describe('when "query parser" an unknown value', function () { it('should throw', function () { - createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/); + assert.throws(createApp.bind(null, 'bogus'), + /unknown value.*query parser/) }); }); }) diff --git a/test/req.route.js b/test/req.route.js index 2947b7c3d0..b32d470bd6 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -8,18 +8,20 @@ describe('req', function(){ var app = express(); app.get('/user/:id/:op?', function(req, res, next){ - req.route.path.should.equal('/user/:id/:op?'); + res.header('path-1', req.route.path) next(); }); app.get('/user/:id/edit', function(req, res){ - req.route.path.should.equal('/user/:id/edit'); + res.header('path-2', req.route.path) res.end(); }); request(app) - .get('/user/12/edit') - .expect(200, done); + .get('/user/12/edit') + .expect('path-1', '/user/:id/:op?') + .expect('path-2', '/user/:id/edit') + .expect(200, done) }) }) }) diff --git a/test/req.xhr.js b/test/req.xhr.js index 94af9170cb..3ad1c6fb72 100644 --- a/test/req.xhr.js +++ b/test/req.xhr.js @@ -4,59 +4,38 @@ var express = require('../') describe('req', function(){ describe('.xhr', function(){ - it('should return true when X-Requested-With is xmlhttprequest', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); + before(function () { + this.app = express() + this.app.get('/', function (req, res) { + res.send(req.xhr) + }) + }) - request(app) - .get('/') - .set('X-Requested-With', 'xmlhttprequest') - .expect(200, done) + it('should return true when X-Requested-With is xmlhttprequest', function(done){ + request(this.app) + .get('/') + .set('X-Requested-With', 'xmlhttprequest') + .expect(200, 'true', done) }) it('should case-insensitive', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'XMLHttpRequest') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'XMLHttpRequest') + .expect(200, 'true', done) }) it('should return false otherwise', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'blahblah') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'blahblah') + .expect(200, 'false', done) }) it('should return false when not present', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .expect(200, done) + request(this.app) + .get('/') + .expect(200, 'false', done) }) }) }) diff --git a/test/res.cookie.js b/test/res.cookie.js index d8e6b7ca85..8f8662c217 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -1,7 +1,6 @@ var express = require('../') , request = require('supertest') - , cookie = require('cookie') , cookieParser = require('cookie-parser') var merge = require('utils-merge'); @@ -46,12 +45,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .get('/') + .expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path=/,gender=%3F; Path=/') + .expect(200, done) }) }) @@ -80,11 +76,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT'); - done(); - }) + .get('/') + .expect('Set-Cookie', /name=tobi; Max-Age=1; Path=\/; Expires=/) + .expect(200, done) }) it('should set max-age', function(done){ @@ -141,13 +135,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = res.headers['set-cookie'][0]; - val = cookie.parse(val.split('.')[0]); - val.user.should.equal('s:j:{"name":"tobi"}'); - done(); - }) + .get('/') + .expect('Set-Cookie', 'user=s%3Aj%3A%7B%22name%22%3A%22tobi%22%7D.K20xcwmDS%2BPb1rsD95o5Jm5SqWs1KteqdnynnB7jkTE; Path=/') + .expect(200, done) }) }) diff --git a/test/res.send.js b/test/res.send.js index b836b5e4dc..e62caf95dc 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -544,7 +544,7 @@ describe('res', function(){ var chunk = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body; - chunk.toString().should.equal('hello, world!'); + assert.strictEqual(chunk.toString(), 'hello, world!') return '"custom"'; }); diff --git a/test/utils.js b/test/utils.js index b51d223af9..a0fac7a722 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,27 +1,28 @@ 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(){ it('should support strings', function(){ - utils.etag('express!') - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag('express!'), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.etag('express❤', 'utf8') - .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.etag('express❤', 'utf8'), + '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.etag(Buffer.from('express!')) - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag(Buffer.from('express!')), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.etag('') - .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.etag(''), + '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -49,23 +50,23 @@ describe('utils.setCharset(type, charset)', function () { describe('utils.wetag(body, encoding)', function(){ it('should support strings', function(){ - utils.wetag('express!') - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag('express!'), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.wetag('express❤', 'utf8') - .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.wetag('express❤', 'utf8'), + 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.wetag(Buffer.from('express!')) - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag(Buffer.from('express!')), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.wetag('') - .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.wetag(''), + 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -89,7 +90,7 @@ describe('utils.isAbsolute()', function(){ describe('utils.flatten(arr)', function(){ it('should flatten an array', function(){ var arr = ['one', ['two', ['three', 'four'], 'five']]; - utils.flatten(arr) - .should.eql(['one', 'two', 'three', 'four', 'five']); + should(utils.flatten(arr)) + .eql(['one', 'two', 'three', 'four', 'five']) }) })