@@ -1655,14 +1655,29 @@ describe('model: findOneAndUpdate:', function() {
1655
1655
} ) ;
1656
1656
} ) ;
1657
1657
1658
- it ( 'strictQuery option (gh-4136)' , function ( done ) {
1659
- const modelSchema = new Schema ( { field : Number } , { strictQuery : 'throw' } ) ;
1658
+ it ( 'strictQuery option (gh-4136) (gh-7152)' , function ( ) {
1659
+ const modelSchema = new Schema ( {
1660
+ field : Number ,
1661
+ nested : { path : String }
1662
+ } , { strictQuery : 'throw' } ) ;
1660
1663
1661
1664
const Model = db . model ( 'gh4136' , modelSchema ) ;
1662
- Model . find ( { nonexistingField : 1 } ) . exec ( function ( error ) {
1663
- assert . ok ( error ) ;
1664
- assert . ok ( error . message . indexOf ( 'strictQuery' ) !== - 1 , error . message ) ;
1665
- done ( ) ;
1665
+
1666
+ return co ( function * ( ) {
1667
+ // `find()` on a top-level path not in the schema
1668
+ let err = yield Model . find ( { notInschema : 1 } ) . then ( ( ) => null , e => e ) ;
1669
+ assert . ok ( err ) ;
1670
+ assert . ok ( err . message . indexOf ( 'strictQuery' ) !== - 1 , err . message ) ;
1671
+
1672
+ // Shouldn't throw on nested path re: gh-7152
1673
+ yield Model . create ( { nested : { path : 'a' } } ) ;
1674
+ const doc = yield Model . findOne ( { nested : { path : 'a' } } ) ;
1675
+ assert . ok ( doc ) ;
1676
+
1677
+ // `find()` on a nested path not in the schema
1678
+ err = yield Model . find ( { 'nested.bad' : 'foo' } ) . then ( ( ) => null , e => e ) ;
1679
+ assert . ok ( err ) ;
1680
+ assert . ok ( err . message . indexOf ( 'strictQuery' ) !== - 1 , err . message ) ;
1666
1681
} ) ;
1667
1682
} ) ;
1668
1683
0 commit comments