forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.validation.test.js
71 lines (61 loc) · 1.7 KB
/
errors.validation.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Module dependencies.
*/
var assert = require('assert')
, start = require('./common')
, mongoose = start.mongoose
, EmbeddedDocument = require('../lib/types/embedded')
, DocumentArray = require('../lib/types/documentarray')
, Schema = mongoose.Schema
, SchemaType = mongoose.SchemaType
, ValidatorError = SchemaType.ValidatorError
, ValidationError = mongoose.Document.ValidationError
describe('ValidationError', function(){
describe('#infiniteRecursion', function(){
it('does not cause RangeError (gh-1834)', function(done){
var SubSchema
, M
, model;
SubSchema = new Schema({
name: {type: String, required: true},
contents: [new Schema({
key: {type: String, required: true},
value: {type: String, required: true}
}, {_id: false})]
});
M = mongoose.model('SubSchema', SubSchema);
model = new M({
name: 'Model',
contents: [
{ key: 'foo' }
]
});
model.validate(function(err){
assert.doesNotThrow(function(){
JSON.stringify(err);
});
done();
});
})
});
describe('#toString', function(){
it('does not cause RangeError (gh-1296)', function(done){
var ASchema = new Schema({
key: {type: String, required: true}
, value: {type:String, required: true}
});
var BSchema = new Schema({
contents: [ASchema]
});
var M = mongoose.model('A', BSchema);
var m = new M;
m.contents.push({ key: 'asdf' });
m.validate(function (err) {
assert.doesNotThrow(function(){
String(err)
});
done();
});
})
})
});