File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -13843,6 +13843,36 @@ describe('document', function() {
13843
13843
assert . strictEqual ( requiredCalls [ 0 ] , doc . config . prop ) ;
13844
13844
assert . strictEqual ( requiredCalls [ 1 ] , doc . config . prop ) ;
13845
13845
} ) ;
13846
+
13847
+ it ( 'applies toObject() getters to 3 level deep subdocuments (gh-14840) (gh-14835)' , async function ( ) {
13848
+ // Define nested schemas
13849
+ const Level3Schema = new mongoose . Schema ( {
13850
+ property : {
13851
+ type : String ,
13852
+ get : ( value ) => value ? value . toUpperCase ( ) : value
13853
+ }
13854
+ } ) ;
13855
+
13856
+ const Level2Schema = new mongoose . Schema ( { level3 : Level3Schema } ) ;
13857
+ const Level1Schema = new mongoose . Schema ( { level2 : Level2Schema } ) ;
13858
+ const MainSchema = new mongoose . Schema ( { level1 : Level1Schema } ) ;
13859
+ const MainModel = db . model ( 'Test' , MainSchema ) ;
13860
+
13861
+ const doc = await MainModel . create ( {
13862
+ level1 : {
13863
+ level2 : {
13864
+ level3 : {
13865
+ property : 'testValue'
13866
+ }
13867
+ }
13868
+ }
13869
+ } ) ;
13870
+
13871
+ // Fetch and convert the document to an object with getters applied
13872
+ const result = await MainModel . findById ( doc . _id ) ;
13873
+ const objectWithGetters = result . toObject ( { getters : true , virtuals : false } ) ;
13874
+ assert . strictEqual ( objectWithGetters . level1 . level2 . level3 . property , 'TESTVALUE' ) ;
13875
+ } ) ;
13846
13876
} ) ;
13847
13877
13848
13878
describe ( 'Check if instance function that is supplied in schema option is available' , function ( ) {
You can’t perform that action at this time.
0 commit comments