forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.mixed.test.js
38 lines (33 loc) · 1.1 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
36
37
38
'use strict';
/**
* Module dependencies.
*/
const start = require('./common');
const assert = require('assert');
const mongoose = new start.mongoose.Mongoose();
const 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) {
const s = new Schema({ mix: { type: Schema.Types.Mixed, default: {} } });
const M = mongoose.model('M1', s);
const m1 = new M();
const m2 = new M();
m1.mix.val = 3;
assert.equal(m1.mix.val, 3);
assert.equal(m2.mix.val, undefined);
done();
});
it('can be forced to share the object between documents', function(done) {
// silly but necessary for backwards compatibility
const s = new Schema({ mix: { type: Schema.Types.Mixed, default: {}, shared: true } });
const M = mongoose.model('M2', s);
const m1 = new M();
const m2 = new M();
m1.mix.val = 3;
assert.equal(m1.mix.val, 3);
assert.equal(m2.mix.val, 3);
done();
});
});
});