Merge pull request #421 from strongloop/feature/update-should
Update to `should` to the latest version 4.6.3
This commit is contained in:
commit
9b675ef3dc
|
@ -24,7 +24,7 @@
|
|||
],
|
||||
"devDependencies": {
|
||||
"mocha": "~1.20.1",
|
||||
"should": "^1.3.0"
|
||||
"should": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "~0.9.0",
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('datatypes', function () {
|
|||
before(function (done) {
|
||||
db = getSchema();
|
||||
Nested = db.define('Nested', {});
|
||||
|
||||
|
||||
Model = db.define('Model', {
|
||||
str: String,
|
||||
date: Date,
|
||||
|
@ -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,15 +112,15 @@ 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();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
it('should not coerce nested objects into ModelConstructor types', function() {
|
||||
var coerced = Model._coerce({ nested: { foo: 'bar' } });
|
||||
coerced.nested.constructor.name.should.equal('Object');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -35,7 +35,7 @@ describe('defaults', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should ignore defaults with limited fields', function (done) {
|
||||
Server.create({ host: 'localhost', port: 8080 }, function(err, s) {
|
||||
should.not.exist(err);
|
||||
|
@ -43,10 +43,10 @@ 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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -79,7 +79,7 @@ describe('include', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fetch Passport - Owner - Posts - alternate syntax', function (done) {
|
||||
Passport.find({include: {owner: {relation: 'posts'}}}, function (err, passports) {
|
||||
should.not.exist(err);
|
||||
|
@ -120,7 +120,7 @@ describe('include', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fetch Passports with include scope on Posts', function (done) {
|
||||
Passport.find({
|
||||
include: {owner: {relation: 'posts', scope:{
|
||||
|
@ -131,31 +131,31 @@ describe('include', function () {
|
|||
should.not.exist(err);
|
||||
should.exist(passports);
|
||||
passports.length.should.equal(3);
|
||||
|
||||
|
||||
var passport = passports[0];
|
||||
passport.number.should.equal('1');
|
||||
passport.owner().name.should.equal('User A');
|
||||
var owner = passport.owner().toObject();
|
||||
|
||||
|
||||
var posts = passport.owner().posts();
|
||||
posts.should.be.an.array;
|
||||
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');
|
||||
|
||||
|
||||
posts[1].title.should.equal('Post B');
|
||||
posts[1].author().name.should.equal('User A');
|
||||
|
||||
|
||||
posts[2].title.should.equal('Post A');
|
||||
posts[2].author().name.should.equal('User A');
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fetch Users with include scope on Posts - belongsTo', function (done) {
|
||||
Post.find({
|
||||
include: { relation: 'author', scope:{ fields: ['name'] }}
|
||||
|
@ -163,16 +163,16 @@ describe('include', function () {
|
|||
should.not.exist(err);
|
||||
should.exist(posts);
|
||||
posts.length.should.equal(5);
|
||||
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fetch Users with include scope on Posts - hasMany', function (done) {
|
||||
User.find({
|
||||
include: {relation: 'posts', scope:{
|
||||
|
@ -182,27 +182,27 @@ describe('include', function () {
|
|||
should.not.exist(err);
|
||||
should.exist(users);
|
||||
users.length.should.equal(5);
|
||||
|
||||
|
||||
users[0].name.should.equal('User A');
|
||||
users[1].name.should.equal('User B');
|
||||
|
||||
|
||||
var posts = users[0].posts();
|
||||
posts.should.be.an.array;
|
||||
posts.should.have.length(3);
|
||||
|
||||
|
||||
posts[0].title.should.equal('Post C');
|
||||
posts[1].title.should.equal('Post B');
|
||||
posts[2].title.should.equal('Post A');
|
||||
|
||||
|
||||
var posts = users[1].posts();
|
||||
posts.should.be.an.array;
|
||||
posts.should.have.length(1);
|
||||
posts[0].title.should.equal('Post D');
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fetch Users with include scope on Passports - hasMany', function (done) {
|
||||
User.find({
|
||||
include: {relation: 'passports', scope:{
|
||||
|
@ -212,14 +212,14 @@ describe('include', function () {
|
|||
should.not.exist(err);
|
||||
should.exist(users);
|
||||
users.length.should.equal(5);
|
||||
|
||||
|
||||
users[0].name.should.equal('User A');
|
||||
users[0].passports().should.be.empty;
|
||||
|
||||
|
||||
users[1].name.should.equal('User B');
|
||||
var passports = users[1].passports();
|
||||
passports[0].number.should.equal('2');
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -317,23 +317,23 @@ describe('include', function () {
|
|||
should.exists(parts);
|
||||
parts.length.should.equal(1);
|
||||
parts[0].partNumber.should.equal('engine');
|
||||
|
||||
|
||||
// Create a part
|
||||
assembly.parts.create({partNumber: 'door'}, function (err, part4) {
|
||||
|
||||
|
||||
Assembly.find({include: 'parts'}, function (err, assemblies) {
|
||||
assemblies.length.should.equal(1);
|
||||
assemblies[0].parts().length.should.equal(2);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Not implemented correctly, see: loopback-datasource-juggler/issues/166
|
||||
//
|
||||
// it('should support include scope on hasAndBelongsToMany', function (done) {
|
||||
|
|
|
@ -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);
|
||||
|
@ -622,11 +622,11 @@ describe('DataSource define model', function () {
|
|||
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should allow an explicit remoting path', function () {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
var User = ds.define('User', {name: String, bio: String}, {
|
||||
|
||||
var User = ds.define('User', {name: String, bio: String}, {
|
||||
http: { path: 'accounts' }
|
||||
});
|
||||
User.http.path.should.equal('/accounts');
|
||||
|
@ -652,7 +652,7 @@ describe('Load models with base', function () {
|
|||
assert(Customer.prototype.instanceMethod === User.prototype.instanceMethod);
|
||||
assert.equal(Customer.base, User);
|
||||
assert.equal(Customer.base, Customer.super_);
|
||||
|
||||
|
||||
try {
|
||||
var Customer1 = ds.define('Customer1', {vip: Boolean}, {base: 'User1'});
|
||||
} catch (e) {
|
||||
|
@ -949,37 +949,37 @@ describe('Load models with relations', function () {
|
|||
assert(Post.relations['user']);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should set up referencesMany relations', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
|
||||
var Post = ds.define('Post', {userId: Number, content: String});
|
||||
var User = ds.define('User', {name: String}, {relations: {posts: {type: 'referencesMany', model: 'Post'}}});
|
||||
|
||||
|
||||
assert(User.relations['posts']);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should set up embedsMany relations', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
|
||||
var Post = ds.define('Post', {userId: Number, content: String});
|
||||
var User = ds.define('User', {name: String}, {relations: {posts: {type: 'embedsMany', model: 'Post' }}});
|
||||
|
||||
|
||||
assert(User.relations['posts']);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should set up polymorphic relations', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
|
||||
var Author = ds.define('Author', {name: String}, {relations: {
|
||||
pictures: {type: 'hasMany', model: 'Picture', polymorphic: 'imageable'}
|
||||
}});
|
||||
var Picture = ds.define('Picture', {name: String}, {relations: {
|
||||
imageable: {type: 'belongsTo', polymorphic: true}
|
||||
}});
|
||||
|
||||
|
||||
assert(Author.relations['pictures']);
|
||||
assert.deepEqual(Author.relations['pictures'].toJSON(), {
|
||||
name: 'pictures',
|
||||
|
@ -989,13 +989,13 @@ describe('Load models with relations', function () {
|
|||
modelTo: 'Picture',
|
||||
keyTo: 'imageableId',
|
||||
multiple: true,
|
||||
polymorphic: {
|
||||
polymorphic: {
|
||||
as: 'imageable',
|
||||
foreignKey: 'imageableId',
|
||||
discriminator: 'imageableType'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assert(Picture.relations['imageable']);
|
||||
assert.deepEqual(Picture.relations['imageable'].toJSON(), {
|
||||
name: 'imageable',
|
||||
|
@ -1005,7 +1005,7 @@ describe('Load models with relations', function () {
|
|||
modelTo: '<polymorphic>',
|
||||
keyTo: 'id',
|
||||
multiple: false,
|
||||
polymorphic: {
|
||||
polymorphic: {
|
||||
as: 'imageable',
|
||||
foreignKey: 'imageableId',
|
||||
discriminator: 'imageableType'
|
||||
|
@ -1013,7 +1013,7 @@ describe('Load models with relations', function () {
|
|||
});
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should set up foreign key with the correct type', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
|
@ -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) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue