forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.mixed.test.js
35 lines (32 loc) · 1.02 KB
/
schema.mixed.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Module dependencies.
*/
var start = require('./common')
, mongoose = new start.mongoose.Mongoose
, assert = require('assert')
, Schema = mongoose.Schema
describe('schematype mixed', function(){
describe('empty object defaults (gh-1380)', function(){
it('are interpreted as fns that return new empty objects', function(done){
var s = Schema({ mix: { type: Schema.Types.Mixed, default: {} }})
var M = mongoose.model('M1', s);
var m1 = new M;
var m2 = new M;
m1.mix.val = 3;
assert.equal(3, m1.mix.val);
assert.equal(undefined, m2.mix.val);
done();
})
it('can be forced to share the object between documents', function(done){
// silly but necessary for backwards compatibility
var s = Schema({ mix: { type: Schema.Types.Mixed, default: {}, shared: true }})
var M = mongoose.model('M2', s);
var m1 = new M;
var m2 = new M;
m1.mix.val = 3;
assert.equal(3, m1.mix.val);
assert.equal(3, m2.mix.val);
done();
})
})
})