@@ -457,4 +457,88 @@ describe("helpers", () => {
457
457
_ . each ( getPidFromiOSSimulatorLogsTestData , testData => assertPidTestData ( testData ) ) ;
458
458
} ) ;
459
459
} ) ;
460
+
461
+ describe ( "getValueFromNestedObject" , ( ) => {
462
+ interface IValueFromNestedObjectTestData extends ITestData {
463
+ key : string ;
464
+ }
465
+
466
+ const key = "key" ;
467
+ const dollarKey = "$key" ;
468
+ const dollarTestObj = { [ dollarKey ] : "value" } ;
469
+ const serviceKey = "keyEndingWithService" ;
470
+ const serviceTestObj = { [ serviceKey ] : "value" } ;
471
+ const testObj = { key } ;
472
+ const getValueFromNestedObjectTestData : IValueFromNestedObjectTestData [ ] = [
473
+ {
474
+ key,
475
+ input : { } ,
476
+ expectedResult : undefined
477
+ } ,
478
+ {
479
+ key,
480
+ input : testObj ,
481
+ expectedResult : testObj
482
+ } ,
483
+ {
484
+ key,
485
+ input : { nestedKey : testObj } ,
486
+ expectedResult : testObj
487
+ } ,
488
+ {
489
+ key,
490
+ input : { nestedKey : { anotherNestedKey : testObj } } ,
491
+ expectedResult : testObj
492
+ } ,
493
+ {
494
+ key,
495
+ input : { otherKey : "otherValue" } ,
496
+ expectedResult : undefined
497
+ } ,
498
+ {
499
+ key,
500
+ input : { otherKey : "otherValue" } ,
501
+ expectedResult : undefined
502
+ } ,
503
+ {
504
+ key : dollarKey ,
505
+ input : dollarTestObj ,
506
+ expectedResult : dollarTestObj
507
+ } ,
508
+ {
509
+ key : dollarKey ,
510
+ input : { nestedKey : dollarTestObj } ,
511
+ expectedResult : dollarTestObj
512
+ } ,
513
+ {
514
+ key : dollarKey ,
515
+ input : { "$nestedKey" : dollarTestObj } ,
516
+ expectedResult : undefined
517
+ } ,
518
+ {
519
+ key : serviceKey ,
520
+ input : serviceTestObj ,
521
+ expectedResult : serviceTestObj
522
+ } ,
523
+ {
524
+ key : serviceKey ,
525
+ input : { nestedKey : serviceTestObj } ,
526
+ expectedResult : serviceTestObj
527
+ } ,
528
+ {
529
+ key : serviceKey ,
530
+ input : { nestedKeyService : serviceTestObj } ,
531
+ expectedResult : undefined
532
+ }
533
+ ] ;
534
+
535
+ const assertValueFromNestedObjectTestData = ( testData : IValueFromNestedObjectTestData ) => {
536
+ const actualResult = helpers . getValueFromNestedObject ( testData . input , testData . key ) ;
537
+ assert . deepEqual ( actualResult , testData . expectedResult , `For input ${ JSON . stringify ( testData . input ) } , the expected result is: ${ JSON . stringify ( testData . expectedResult || "undefined" ) } , but actual result is: ${ JSON . stringify ( actualResult || "undefined" ) } .` ) ;
538
+ } ;
539
+
540
+ it ( "returns expected result" , ( ) => {
541
+ _ . each ( getValueFromNestedObjectTestData , testData => assertValueFromNestedObjectTestData ( testData ) ) ;
542
+ } ) ;
543
+ } ) ;
460
544
} ) ;
0 commit comments