Merge pull request #421 from strongloop/feature/update-should

Update to `should` to the latest version 4.6.3
This commit is contained in:
Miroslav Bajtoš 2015-02-03 19:38:39 +01:00
commit 9b675ef3dc
7 changed files with 380 additions and 376 deletions

View File

@ -24,7 +24,7 @@
],
"devDependencies": {
"mocha": "~1.20.1",
"should": "^1.3.0"
"should": "^4.6.3"
},
"dependencies": {
"async": "~0.9.0",

View File

@ -29,11 +29,11 @@ describe('datatypes', function () {
Model.create({
str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str']
}, function (err, m) {
should.not.exist(err);
should.not.exists(err);
should.exist(m && m.id);
m.str.should.be.a('string');
m.num.should.be.a('number');
m.bool.should.be.a('boolean');
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
m.list[0].should.be.equal('test');
m.arr[0].should.be.equal(1);
m.arr[1].should.be.equal('str');
@ -45,9 +45,9 @@ describe('datatypes', function () {
Model.findById(id, function (err, m) {
should.not.exist(err);
should.exist(m);
m.str.should.be.a('string');
m.num.should.be.a('number');
m.bool.should.be.a('boolean');
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
m.list[0].should.be.equal('test');
m.arr[0].should.be.equal(1);
m.arr[1].should.be.equal('str');
@ -61,9 +61,9 @@ describe('datatypes', function () {
Model.findOne(function (err, m) {
should.not.exist(err);
should.exist(m);
m.str.should.be.a('string');
m.num.should.be.a('number');
m.bool.should.be.a('boolean');
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
m.date.should.be.an.instanceOf(Date);
m.date.toString().should.equal(d.toString(), 'Time must match');
done();
@ -81,9 +81,9 @@ describe('datatypes', function () {
should.exist(m && m.id);
// sanity check initial types
m.str.should.be.a('string');
m.num.should.be.a('number');
m.bool.should.be.a('boolean');
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
id = m.id;
testDataInDB(function () {
testUpdate(function() {
@ -101,7 +101,7 @@ describe('datatypes', function () {
id: id, num: '10'
}, function (err, m) {
should.not.exist(err);
m.num.should.be.a('number');
m.num.should.be.type('number');
done();
});
});
@ -112,7 +112,7 @@ describe('datatypes', function () {
// verify that the value stored in the db is still an object
db.connector.find(Model.modelName, id, function (err, data) {
should.exist(data);
data.num.should.be.a('number');
data.num.should.be.type('number');
done();
});
}

View File

@ -43,7 +43,7 @@ describe('defaults', function () {
Server.find({ fields: ['host'] }, function (err, servers) {
servers[0].host.should.equal('localhost');
servers[0].should.have.property('host');
servers[0].should.not.have.property('port');
servers[0].should.have.property('port', undefined);
done();
});
});

View File

@ -142,7 +142,7 @@ describe('include', function () {
posts.should.have.length(3);
posts[0].title.should.equal('Post C');
posts[0].should.not.have.property('id'); // omitted
posts[0].should.have.property('id', undefined); // omitted
posts[0].author().should.be.instanceOf(User);
posts[0].author().name.should.equal('User A');
@ -167,7 +167,7 @@ describe('include', function () {
var author = posts[0].author();
author.name.should.equal('User A');
author.should.have.property('id');
author.should.not.have.property('age');
author.should.have.property('age', undefined);
done();
});

View File

@ -25,17 +25,17 @@ describe('ModelBuilder define model', function () {
return this.name + ', ' + this.age;
};
modelBuilder.models.should.be.a('object').and.have.property('User', User);
modelBuilder.definitions.should.be.a('object').and.have.property('User');
modelBuilder.models.should.be.type('object').and.have.property('User').exactly(User);
modelBuilder.definitions.should.be.type('object').and.have.property('User');
var user = new User({name: 'Joe', age: 20, xyz: false});
User.modelName.should.equal('User');
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.have.property('xyz', false);
user.should.not.have.property('bio');
user.should.have.property('bio', undefined);
done(null, User);
});
@ -47,12 +47,12 @@ describe('ModelBuilder define model', function () {
var user = new User({name: 'Joe', age: 20});
User.modelName.should.equal('User');
user.should.be.a('object');
user.should.be.type('object');
user.should.have.property('name', 'Joe');
user.should.not.have.property('age');
user.toObject().should.not.have.property('age');
user.toObject(true).should.not.have.property('age');
user.should.not.have.property('bio');
user.should.have.property('bio', undefined);
done(null, User);
});
@ -102,7 +102,7 @@ describe('ModelBuilder define model', function () {
var user = new User({name: 'Joe', age: 20});
User.modelName.should.equal('User');
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
@ -142,7 +142,7 @@ describe('ModelBuilder define model', function () {
var user = new User({name: 'Joe', age: 20});
User.modelName.should.equal('User');
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
@ -180,8 +180,8 @@ describe('ModelBuilder define model', function () {
return this.name + ', ' + this.age;
};
modelBuilder.models.should.be.a('object').and.have.property('User', User);
modelBuilder.definitions.should.be.a('object').and.have.property('User');
modelBuilder.models.should.be.type('object').and.have.property('User', User);
modelBuilder.definitions.should.be.type('object').and.have.property('User');
var user = new User({
name: 'Joe', age: 20,
@ -193,10 +193,10 @@ describe('ModelBuilder define model', function () {
});
User.modelName.should.equal('User');
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
user.should.have.property('bio', undefined);
user.should.have.property('address');
user.address.should.have.property('city', 'San Jose');
user.address.should.have.property('state', 'CA');
@ -236,7 +236,7 @@ describe('ModelBuilder define model', function () {
User.modelName.should.equal('User');
User.definition.properties.address.should.have.property('type', Address);
user.should.be.a('object');
user.should.be.type('object');
assert(user.name === 'Joe');
user.address.should.have.property('city', 'San Jose');
user.address.should.have.property('state', 'CA');
@ -432,7 +432,7 @@ describe('DataSource define model', function () {
User.create({name: 'Joe', age: 20}, function (err, user) {
User.modelName.should.equal('User');
user.should.be.a('object');
user.should.be.type('object');
assert(user.name === 'Joe');
assert(user.age === undefined);
assert(user.toObject().age === undefined);
@ -464,13 +464,13 @@ describe('DataSource define model', function () {
User.create({name: 'Joe', age: 20}, function (err, user) {
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
User.findById(user.id, function (err, user) {
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
@ -487,7 +487,7 @@ describe('DataSource define model', function () {
User.create({name: 'Joe', age: 20}, function (err, user) {
User.modelName.should.equal('User');
user.should.be.a('object').and.have.property('name', 'Joe');
user.should.be.type('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.not.have.property('bio');
@ -504,7 +504,7 @@ describe('DataSource define model', function () {
var user = new User({name: 'Joe', age: 20});
User.modelName.should.equal('User');
user.should.be.a('object');
user.should.be.type('object');
assert(user.name === 'Joe');
assert(user.age === undefined);
assert(user.toObject().age === undefined);
@ -550,7 +550,7 @@ describe('DataSource define model', function () {
var user = new User({name: 'Joe', age: 20}, {strict: false});
user.should.have.property('__strict', false);
user.should.be.a('object');
user.should.be.type('object');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.toObject().should.have.property('age', 20);
@ -1533,11 +1533,11 @@ describe('Load models from json', function () {
var customer = new Customer({name: 'Joe', age: 20, customerId: 'c01'});
customer.should.be.a('object').and.have.property('name', 'Joe');
customer.should.be.type('object').and.have.property('name', 'Joe');
customer.should.have.property('name', 'Joe');
customer.should.have.property('age', 20);
customer.should.have.property('customerId', 'c01');
customer.should.not.have.property('bio');
customer.should.have.property('bio', undefined);
// The properties are defined at prototype level
assert.equal(Object.keys(customer).filter(function (k) {

View File

@ -47,8 +47,8 @@ describe('relations', function () {
b.chapters.should.be.an.instanceOf(Function);
b.users.should.be.an.instanceOf(Function);
b.authors.should.be.an.instanceOf(Function);
Object.keys((new Chapter).toObject()).should.include('bookId');
Object.keys((new Author).toObject()).should.include('projectId');
Object.keys((new Chapter).toObject()).should.containEql('bookId');
Object.keys((new Author).toObject()).should.containEql('projectId');
db.automigrate(done);
});
@ -56,7 +56,7 @@ describe('relations', function () {
it('can be declared in short form', function (done) {
Author.hasMany('readers');
(new Author).readers.should.be.an.instanceOf(Function);
Object.keys((new Reader).toObject()).should.include('authorId');
Object.keys((new Reader).toObject()).should.containEql('authorId');
db.autoupdate(done);
});
@ -1561,12 +1561,12 @@ describe('relations', function () {
// syntax 1 (old)
Item.belongsTo(List);
Object.keys((new Item).toObject()).should.include('listId');
Object.keys((new Item).toObject()).should.containEql('listId');
(new Item).list.should.be.an.instanceOf(Function);
// syntax 2 (new)
Fear.belongsTo('mind');
Object.keys((new Fear).toObject()).should.include('mindId');
Object.keys((new Fear).toObject()).should.containEql('mindId');
(new Fear).mind.should.be.an.instanceOf(Function);
// (new Fear).mind.build().should.be.an.instanceOf(Mind);
});
@ -1709,8 +1709,8 @@ describe('relations', function () {
p.personId.should.eql(personCreated.id);
p.person(function(err, person) {
person.name.should.equal('Fred');
person.should.not.have.property('age');
person.should.not.have.property('passportNotes');
person.should.have.property('age', undefined);
person.should.have.property('passportNotes', undefined);
done();
});
});
@ -1769,7 +1769,7 @@ describe('relations', function () {
it('can be declared using hasOne method', function () {
Supplier.hasOne(Account, { properties: { name: 'supplierName' } });
Object.keys((new Account()).toObject()).should.include('supplierId');
Object.keys((new Account()).toObject()).should.containEql('supplierId');
(new Supplier()).account.should.be.an.instanceOf(Function);
});
@ -1948,7 +1948,7 @@ describe('relations', function () {
properties: {name: 'supplierName'},
foreignKey: 'sid'
});
Object.keys((new Account()).toObject()).should.include('sid');
Object.keys((new Account()).toObject()).should.containEql('sid');
(new Supplier()).account.should.be.an.instanceOf(Function);
});

View File

@ -13,13 +13,17 @@ describe('dataSource', function () {
});
it('should clone existing model', function () {
// Workaround for a possible bug in `should`
// where it takes ages to evaluate `should.equal` for complex objects
this.timeout(20000);
SlaveModel = slave.copyModel(Model);
SlaveModel.dataSource.should.eql(slave);
slave.should.not.eql(db);
SlaveModel.dataSource.should.equal(slave);
slave.should.not.equal(db);
var sm = new SlaveModel;
sm.should.be.instanceOf(Model);
sm.getDataSource().should.not.eql(db);
sm.getDataSource().should.eql(slave);
sm.getDataSource().should.not.equal(db);
sm.getDataSource().should.equal(slave);
});
it('should automigrate', function (done) {