@@ -122,4 +122,55 @@ describe('Utils', () => {
122122 expect ( result ) . toBe ( '{"name":"test","number":42,"nested":{"key":"value"}}' ) ;
123123 } ) ;
124124 } ) ;
125+
126+ describe ( 'getNestedProperty' , ( ) => {
127+ it ( 'should get top-level property' , ( ) => {
128+ const obj = { foo : 'bar' } ;
129+ expect ( Utils . getNestedProperty ( obj , 'foo' ) ) . toBe ( 'bar' ) ;
130+ } ) ;
131+
132+ it ( 'should get nested property with dot notation' , ( ) => {
133+ const obj = { database : { options : { enabled : true } } } ;
134+ expect ( Utils . getNestedProperty ( obj , 'database.options.enabled' ) ) . toBe ( true ) ;
135+ } ) ;
136+
137+ it ( 'should return undefined for non-existent property' , ( ) => {
138+ const obj = { foo : 'bar' } ;
139+ expect ( Utils . getNestedProperty ( obj , 'baz' ) ) . toBeUndefined ( ) ;
140+ } ) ;
141+
142+ it ( 'should return undefined for non-existent nested property' , ( ) => {
143+ const obj = { database : { options : { } } } ;
144+ expect ( Utils . getNestedProperty ( obj , 'database.options.enabled' ) ) . toBeUndefined ( ) ;
145+ } ) ;
146+
147+ it ( 'should return undefined when path traverses non-object' , ( ) => {
148+ const obj = { database : 'string' } ;
149+ expect ( Utils . getNestedProperty ( obj , 'database.options.enabled' ) ) . toBeUndefined ( ) ;
150+ } ) ;
151+
152+ it ( 'should return undefined for null object' , ( ) => {
153+ expect ( Utils . getNestedProperty ( null , 'foo' ) ) . toBeUndefined ( ) ;
154+ } ) ;
155+
156+ it ( 'should return undefined for empty path' , ( ) => {
157+ const obj = { foo : 'bar' } ;
158+ expect ( Utils . getNestedProperty ( obj , '' ) ) . toBeUndefined ( ) ;
159+ } ) ;
160+
161+ it ( 'should handle value of 0' , ( ) => {
162+ const obj = { database : { timeout : 0 } } ;
163+ expect ( Utils . getNestedProperty ( obj , 'database.timeout' ) ) . toBe ( 0 ) ;
164+ } ) ;
165+
166+ it ( 'should handle value of false' , ( ) => {
167+ const obj = { database : { enabled : false } } ;
168+ expect ( Utils . getNestedProperty ( obj , 'database.enabled' ) ) . toBe ( false ) ;
169+ } ) ;
170+
171+ it ( 'should handle value of empty string' , ( ) => {
172+ const obj = { database : { name : '' } } ;
173+ expect ( Utils . getNestedProperty ( obj , 'database.name' ) ) . toBe ( '' ) ;
174+ } ) ;
175+ } ) ;
125176} ) ;
0 commit comments