@@ -485,6 +485,52 @@ describe('Maybe', () => {
485
485
486
486
} )
487
487
488
+ describe ( 'chain' , ( ) => {
489
+ it ( 'should' , ( ) => {
490
+ interface TestFace { thing : number ; name : string }
491
+ const obj : TestFace = { thing : 1 , name : 'string' }
492
+ const chained = maybe ( obj )
493
+ . project ( a => a . name )
494
+ . map ( a => `${ a } hello` )
495
+
496
+ expect ( chained . isSome ( ) ) . toEqual ( true )
497
+ expect ( chained . valueOrUndefined ( ) ) . toEqual ( 'string hello' )
498
+ } )
499
+
500
+ it ( 'should' , ( ) => {
501
+ const obj = { thing : 1 , name : 'string' , obj : { initial : 'PJM' } }
502
+ const chained = maybe ( obj )
503
+ . project ( a => a . obj )
504
+ . project ( a => a . initial )
505
+ . map ( a => `Hello, ${ a } ` )
506
+
507
+ expect ( chained . isSome ( ) ) . toEqual ( true )
508
+ expect ( chained . valueOrUndefined ( ) ) . toEqual ( 'Hello, PJM' )
509
+ } )
510
+
511
+ it ( 'should' , ( ) => {
512
+ interface TestFace { thing : number ; name : string }
513
+ const obj : TestFace = { thing : 1 , name : undefined as unknown as string }
514
+ const chained = maybe ( obj )
515
+ . project ( a => a . name )
516
+ . project ( a => a )
517
+ . map ( a => `${ a } hello` )
518
+
519
+ expect ( chained . isNone ( ) ) . toEqual ( true )
520
+ expect ( chained . valueOrUndefined ( ) ) . toBeUndefined ( )
521
+ } )
522
+
523
+ it ( 'should' , ( ) => {
524
+ const obj = undefined as unknown as { name : string }
525
+ const chained = maybe ( obj )
526
+ . project ( a => a . name )
527
+ . map ( a => `${ a } hello` )
528
+
529
+ expect ( chained . isNone ( ) ) . toEqual ( true )
530
+ expect ( chained . valueOrUndefined ( ) ) . toBeUndefined ( )
531
+ } )
532
+ } )
533
+
488
534
describe ( 'isSome' , ( ) => {
489
535
it ( 'false path' , ( ) => {
490
536
const sut = undefined as boolean | undefined
@@ -559,7 +605,7 @@ describe('Maybe', () => {
559
605
it ( 'should return result object with success' , ( ) => {
560
606
const hasSome = maybe ( 'hi' )
561
607
const sut = hasSome . toResult ( new Error ( 'oops' ) )
562
-
608
+
563
609
expect ( sut . unwrap ( ) ) . toEqual ( 'hi' )
564
610
} )
565
611
0 commit comments