Skip to content

Commit 2b4b442

Browse files
committed
Fix tests to ensure compatibility w/ should@10
1 parent dafb8a1 commit 2b4b442

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

lib/dao.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ DataAccessObject._coerce = function(where, options) {
17691769
val = utils.toRegExp(val);
17701770
if (val instanceof Error) {
17711771
val.statusCode = 400;
1772-
throw err;
1772+
throw val;
17731773
}
17741774
break;
17751775
}

lib/list.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ List.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
9696
return items;
9797
};
9898

99+
/**
100+
* Convert itself to a plain array.
101+
*
102+
* Some modules such as `should` checks prototype for comparison
103+
*/
104+
List.prototype.toArray = function() {
105+
var items = [];
106+
this.forEach(function(item) {
107+
items.push(item);
108+
});
109+
return items;
110+
};
111+
99112
List.prototype.toJSON = function() {
100113
return this.toObject(true);
101114
};

test/basic-querying.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,12 @@ describe('basic-querying', function() {
10321032
it('should return an error for invalid data types', function(done) {
10331033
// `undefined` is not tested because the `removeUndefined` function
10341034
// in `lib/dao.js` removes it before coercion
1035-
invalidDataTypes.forEach(function(invalidDataType) {
1036-
User.find({where: {name: {regexp: invalidDataType}}}, function(err,
1037-
users) {
1035+
async.each(invalidDataTypes, function(v, cb) {
1036+
User.find({where: {name: {regexp: v}}}, function(err, users) {
10381037
should.exist(err);
1038+
cb();
10391039
});
1040-
});
1041-
done();
1040+
}, done);
10421041
});
10431042
});
10441043
});

test/relations.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,7 +4418,7 @@ describe('relations', function() {
44184418
p.passport.toObject().should.eql({name: 'Anonymous'});
44194419
p.passportItem().should.equal(p.passport);
44204420
p.passportItem(function(err, passport) {
4421-
err.should.not.exist();
4421+
should.not.exist(err);
44224422
passport.should.equal(p.passport);
44234423
});
44244424
});
@@ -6040,8 +6040,8 @@ describe('relations', function() {
60406040
Category.findOne(function(err, cat) {
60416041
cat.jobs.reverse(function(err, ids) {
60426042
var expected = [job3.id, job2.id];
6043-
ids.should.eql(expected);
6044-
cat.jobIds.should.eql(expected);
6043+
ids.toArray().should.eql(expected);
6044+
cat.jobIds.toArray().should.eql(expected);
60456045
done();
60466046
});
60476047
});
@@ -6152,7 +6152,7 @@ describe('relations', function() {
61526152
'should find items on scope with promises', function(done) {
61536153
Category.findOne()
61546154
.then(function(cat) {
6155-
cat.jobIds.should.eql([job2.id]);
6155+
cat.jobIds.toArray().should.eql([job2.id]);
61566156
return cat.jobs.find();
61576157
})
61586158
.then(function(jobs) {
@@ -6352,8 +6352,8 @@ describe('relations', function() {
63526352
return cat.jobs.reverse()
63536353
.then(function(ids) {
63546354
var expected = [job3.id, job2.id];
6355-
ids.should.eql(expected);
6356-
cat.jobIds.should.eql(expected);
6355+
ids.toArray().should.eql(expected);
6356+
cat.jobIds.toArray().should.eql(expected);
63576357
done();
63586358
});
63596359
})
@@ -6382,9 +6382,9 @@ describe('relations', function() {
63826382
.then(function() {
63836383
var expected = [job3.id];
63846384
if (connectorCapabilities.adhocSort !== false) {
6385-
cat.jobIds.should.eql(expected);
6385+
cat.jobIds.toArray().should.eql(expected);
63866386
} else {
6387-
cat.jobIds.should.containDeep(expected);
6387+
cat.jobIds.toArray().should.containDeep(expected);
63886388
}
63896389
return Job.exists(job2.id);
63906390
})

test/validations.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ describe('validations', function() {
848848
User.validatesFormatOf('name', {with: /[a-z][A-Z]*$/, message: CUSTOM_MESSAGE});
849849
var u = new User({name: 'invalid name string 123'});
850850
u.isValid().should.be.false();
851-
u.errors.should.eql({
851+
u.errors.should.containEql({
852852
name: [CUSTOM_MESSAGE],
853853
codes: {
854854
name: ['format'],
@@ -972,14 +972,14 @@ describe('validations', function() {
972972
User.validatesNumericalityOf('age');
973973
var user = new User({age: 'notanumber'});
974974
user.isValid().should.be.false();
975-
user.errors.should.eql({age: ['is not a number']});
975+
user.errors.should.containEql({age: ['is not a number']});
976976
});
977977

978978
it('fails when given undefined values', function() {
979979
User.validatesNumericalityOf('age');
980980
var user = new User({});
981981
user.isValid().should.be.false();
982-
user.errors.should.eql({age: ['is blank']});
982+
user.errors.should.containEql({age: ['is blank']});
983983
});
984984

985985
it('skips undefined values when allowBlank option is true', function() {
@@ -992,14 +992,14 @@ describe('validations', function() {
992992
User.validatesNumericalityOf('age', {allowBlank: true});
993993
var user = new User({age: 'test'});
994994
user.isValid().should.be.false();
995-
user.errors.should.eql({age: ['is not a number']});
995+
user.errors.should.containEql({age: ['is not a number']});
996996
});
997997

998998
it('fails when given null values', function() {
999999
User.validatesNumericalityOf('age');
10001000
var user = new User({age: null});
10011001
user.isValid().should.be.false();
1002-
user.errors.should.eql({age: ['is null']});
1002+
user.errors.should.containEql({age: ['is null']});
10031003
});
10041004

10051005
it('passes when given null values when allowNull option is true', function() {
@@ -1353,7 +1353,7 @@ describe('validations', function() {
13531353
});
13541354
var u = new User({email: 'hello'});
13551355
Boolean(u.isValid()).should.be.false();
1356-
u.errors.should.eql({email: ['Cannot be `hello`']});
1356+
u.errors.should.containEql({email: ['Cannot be `hello`']});
13571357
u.errors.codes.should.eql({email: ['invalid-email']});
13581358
});
13591359

@@ -1470,7 +1470,7 @@ describe('validations', function() {
14701470
User.validatesDateOf('updatedAt');
14711471
var u = new User({updatedAt: 'invalid date string'});
14721472
u.isValid().should.not.be.true();
1473-
u.errors.should.eql({
1473+
u.errors.should.containEql({
14741474
updatedAt: ['is not a valid date'],
14751475
codes: {
14761476
updatedAt: ['date'],
@@ -1494,7 +1494,7 @@ describe('validations', function() {
14941494
});
14951495
var u = new AnotherUser({updatedAt: 'invalid date string'});
14961496
u.isValid().should.not.be.true();
1497-
u.errors.should.eql({
1497+
u.errors.should.containEql({
14981498
updatedAt: ['is not a valid date'],
14991499
codes: {
15001500
updatedAt: ['date'],
@@ -1507,7 +1507,7 @@ describe('validations', function() {
15071507
User.validatesDateOf('updatedAt', {message: CUSTOM_MESSAGE});
15081508
var u = new User({updatedAt: 'invalid date string'});
15091509
u.isValid().should.not.be.true();
1510-
u.errors.should.eql({
1510+
u.errors.should.containEql({
15111511
updatedAt: [CUSTOM_MESSAGE],
15121512
codes: {
15131513
updatedAt: ['date'],

0 commit comments

Comments
 (0)