Skip to content

Commit

Permalink
tests: remove global dependency on should
Browse files Browse the repository at this point in the history
fixes #4797
  • Loading branch information
dougwilson committed Feb 2, 2022
1 parent 215f484 commit bd4fdfe
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 165 deletions.
13 changes: 7 additions & 6 deletions test/app.engine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

var assert = require('assert')
var express = require('../')
, fs = require('fs');
var path = require('path')
Expand All @@ -22,16 +23,16 @@ describe('app', function(){

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){
Expand All @@ -43,7 +44,7 @@ describe('app', function(){

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();
})
})
Expand All @@ -58,7 +59,7 @@ describe('app', function(){

app.render('user', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -73,7 +74,7 @@ describe('app', function(){

app.render('user', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand Down
24 changes: 12 additions & 12 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand All @@ -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, '/')
})
})

Expand All @@ -76,17 +76,17 @@ 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')
})
})

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';
})
})
Expand All @@ -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';
})
})
Expand All @@ -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';
})
})
14 changes: 8 additions & 6 deletions test/app.locals.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

Expand All @@ -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')
})
})
})
30 changes: 14 additions & 16 deletions test/app.param.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

var assert = require('assert')
var express = require('../')
, request = require('supertest');

Expand Down Expand Up @@ -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'))
})
})

Expand All @@ -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)
})
})
})

Expand All @@ -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) {
Expand Down
54 changes: 27 additions & 27 deletions test/app.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -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('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -39,7 +39,7 @@ describe('app', function(){

app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -52,7 +52,7 @@ describe('app', function(){

app.render('blog/post', function (err, str) {
if (err) return done(err);
str.should.equal('<h1>blog post</h1>');
assert.strictEqual(str, '<h1>blog post</h1>')
done();
})
})
Expand All @@ -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();
})
})
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('app', function(){

app.render('email.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>This is an email</p>');
assert.strictEqual(str, '<p>This is an email</p>')
done();
})
})
Expand All @@ -128,7 +128,7 @@ describe('app', function(){

app.render('email', function(err, str){
if (err) return done(err);
str.should.equal('<p>This is an email</p>');
assert.strictEqual(str, '<p>This is an email</p>')
done();
})
})
Expand All @@ -143,7 +143,7 @@ describe('app', function(){

app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -161,7 +161,7 @@ describe('app', function(){

app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<span>tobi</span>');
assert.strictEqual(str, '<span>tobi</span>')
done();
})
})
Expand All @@ -178,7 +178,7 @@ describe('app', function(){

app.render('name.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand Down Expand Up @@ -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();
})
})
Expand All @@ -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();
})
})
Expand All @@ -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();
})
})
Expand All @@ -298,7 +298,7 @@ describe('app', function(){

app.render('user.tmpl', { user: user }, function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -311,7 +311,7 @@ describe('app', function(){

app.render('user.tmpl', {}, function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
Expand All @@ -325,7 +325,7 @@ describe('app', function(){

app.render('user.tmpl', { user: jane }, function (err, str) {
if (err) return done(err);
str.should.equal('<p>jane</p>');
assert.strictEqual(str, '<p>jane</p>')
done();
})
})
Expand All @@ -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();
})
})
Expand Down
Loading

0 comments on commit bd4fdfe

Please sign in to comment.