@@ -101,62 +101,60 @@ describe('Cast Tutorial', function() {
101
101
await query . exec ( ) ;
102
102
} ) ;
103
103
104
- describe ( 'strictQuery' , function ( ) {
105
- it ( 'strictQuery true - simple object' , async function ( ) {
106
- mongoose . deleteModel ( 'Character' ) ;
107
- const schema = new mongoose . Schema ( { name : String , age : Number } , {
108
- strictQuery : true
109
- } ) ;
110
- Character = mongoose . model ( 'Character' , schema ) ;
111
-
112
- const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
113
-
114
- await query . exec ( ) ;
115
- query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
116
- // acquit:ignore:start
117
- assert . deepEqual ( query . getFilter ( ) , { } ) ;
118
- // acquit:ignore:end
104
+ it ( 'strictQuery true' , async function ( ) {
105
+ mongoose . deleteModel ( 'Character' ) ;
106
+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
107
+ strictQuery : true
119
108
} ) ;
109
+ Character = mongoose . model ( 'Character' , schema ) ;
110
+
111
+ const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
112
+
113
+ await query . exec ( ) ;
114
+ query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
115
+ // acquit:ignore:start
116
+ assert . deepEqual ( query . getFilter ( ) , { } ) ;
117
+ // acquit:ignore:end
118
+ } ) ;
119
+
120
+ it ( 'strictQuery throw' , async function ( ) {
121
+ mongoose . deleteModel ( 'Character' ) ;
122
+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
123
+ strictQuery : 'throw'
124
+ } ) ;
125
+ Character = mongoose . model ( 'Character' , schema ) ;
126
+
127
+ const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
120
128
121
- it ( 'strictQuery true - conditions' , async function ( ) {
122
- mongoose . deleteModel ( 'Character' ) ;
123
- const schema = new mongoose . Schema ( { name : String , age : Number } , {
124
- strictQuery : true
125
- } ) ;
126
- Character = mongoose . model ( 'Character' , schema ) ;
127
-
128
- const query = Character . findOne ( {
129
- $or : [ { notInSchema : { $lt : 'not a number' } } ] ,
130
- $and : [ { name : 'abc' } , { age : { $gt : 18 } } , { notInSchema : { $lt : 'not a number' } } ] ,
131
- $nor : [ { } ] // should be kept
132
- } ) ;
133
-
134
- await query . exec ( ) ;
135
- query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
136
- // acquit:ignore:start
137
- assert . deepEqual ( query . getFilter ( ) , { $and : [ { name : 'abc' } , { age : { $gt : 18 } } ] , $nor : [ { } ] } ) ;
138
- // acquit:ignore:end
129
+ const err = await query . exec ( ) . then ( ( ) => null , err => err ) ;
130
+ err . name ; // 'StrictModeError'
131
+ // Path "notInSchema" is not in schema and strictQuery is 'throw'.
132
+ err . message ;
133
+ // acquit:ignore:start
134
+ assert . equal ( err . name , 'StrictModeError' ) ;
135
+ assert . equal ( err . message , 'Path "notInSchema" is not in schema and ' +
136
+ 'strictQuery is \'throw\'.' ) ;
137
+ // acquit:ignore:end
138
+ } ) ;
139
+
140
+ it ( 'strictQuery removes casted empty objects' , async function ( ) {
141
+ mongoose . deleteModel ( 'Character' ) ;
142
+ const schema = new mongoose . Schema ( { name : String , age : Number } , {
143
+ strictQuery : true
139
144
} ) ;
145
+ Character = mongoose . model ( 'Character' , schema ) ;
140
146
141
- it ( 'strictQuery throw' , async function ( ) {
142
- mongoose . deleteModel ( 'Character' ) ;
143
- const schema = new mongoose . Schema ( { name : String , age : Number } , {
144
- strictQuery : 'throw'
145
- } ) ;
146
- Character = mongoose . model ( 'Character' , schema ) ;
147
-
148
- const query = Character . findOne ( { notInSchema : { $lt : 'not a number' } } ) ;
149
-
150
- const err = await query . exec ( ) . then ( ( ) => null , err => err ) ;
151
- err . name ; // 'StrictModeError'
152
- // Path "notInSchema" is not in schema and strictQuery is 'throw'.
153
- err . message ;
154
- // acquit:ignore:start
155
- assert . equal ( err . name , 'StrictModeError' ) ;
156
- assert . equal ( err . message , 'Path "notInSchema" is not in schema and ' +
157
- 'strictQuery is \'throw\'.' ) ;
158
- // acquit:ignore:end
147
+ const query = Character . findOne ( {
148
+ $or : [ { notInSchema : { $lt : 'not a number' } } ] ,
149
+ $and : [ { name : 'abc' } , { age : { $gt : 18 } } , { notInSchema : { $lt : 'not a number' } } ] ,
150
+ $nor : [ { } ] // should be kept
159
151
} ) ;
152
+
153
+ await query . exec ( ) ;
154
+ query . getFilter ( ) ; // Empty object `{}`, Mongoose removes `notInSchema`
155
+ // acquit:ignore:start
156
+ assert . deepEqual ( query . getFilter ( ) , { $and : [ { name : 'abc' } , { age : { $gt : 18 } } ] , $nor : [ { } ] } ) ;
157
+ // acquit:ignore:end
160
158
} ) ;
161
159
162
160
it ( 'implicit in' , async function ( ) {
0 commit comments