@@ -83,6 +83,36 @@ describe('Component Store', () => {
83
83
} )
84
84
) ;
85
85
86
+ it ( 'throws an Error when patchState with an object is called before initialization' , ( ) => {
87
+ const componentStore = new ComponentStore ( ) ;
88
+
89
+ expect ( ( ) => {
90
+ componentStore . patchState ( { foo : 'bar' } ) ;
91
+ } ) . toThrow (
92
+ new Error (
93
+ 'ComponentStore has not been initialized yet. ' +
94
+ 'Please make sure it is initialized before updating/getting.'
95
+ )
96
+ ) ;
97
+ } ) ;
98
+
99
+ it (
100
+ 'throws an Error when patchState with a function/callback is called' +
101
+ ' before initialization' ,
102
+ ( ) => {
103
+ const componentStore = new ComponentStore ( ) ;
104
+
105
+ expect ( ( ) => {
106
+ componentStore . patchState ( ( ) => ( { foo : 'bar' } ) ) ;
107
+ } ) . toThrow (
108
+ new Error (
109
+ 'ComponentStore has not been initialized yet. ' +
110
+ 'Please make sure it is initialized before updating/getting.'
111
+ )
112
+ ) ;
113
+ }
114
+ ) ;
115
+
86
116
it (
87
117
'throws an Error when updater is called before initialization' ,
88
118
marbles ( ( m ) => {
@@ -511,6 +541,47 @@ describe('Component Store', () => {
511
541
) ;
512
542
} ) ;
513
543
544
+ describe ( 'patches the state' , ( ) => {
545
+ interface State {
546
+ value1 : string ;
547
+ value2 : { foo : string } ;
548
+ }
549
+ const INIT_STATE : State = { value1 : 'value1' , value2 : { foo : 'bar' } } ;
550
+ let componentStore : ComponentStore < State > ;
551
+
552
+ beforeEach ( ( ) => {
553
+ componentStore = new ComponentStore ( INIT_STATE ) ;
554
+ } ) ;
555
+
556
+ it (
557
+ 'with a specific value' ,
558
+ marbles ( ( m ) => {
559
+ componentStore . patchState ( { value1 : 'val1' } ) ;
560
+
561
+ m . expect ( componentStore . state$ ) . toBeObservable (
562
+ m . hot ( 's' , {
563
+ s : { ...INIT_STATE , value1 : 'val1' } ,
564
+ } )
565
+ ) ;
566
+ } )
567
+ ) ;
568
+
569
+ it (
570
+ 'with a value based on the previous state' ,
571
+ marbles ( ( m ) => {
572
+ componentStore . patchState ( ( state ) => ( {
573
+ value2 : { foo : `${ state . value2 . foo } 2` } ,
574
+ } ) ) ;
575
+
576
+ m . expect ( componentStore . state$ ) . toBeObservable (
577
+ m . hot ( 's' , {
578
+ s : { ...INIT_STATE , value2 : { foo : 'bar2' } } ,
579
+ } )
580
+ ) ;
581
+ } )
582
+ ) ;
583
+ } ) ;
584
+
514
585
describe ( 'selector' , ( ) => {
515
586
interface State {
516
587
value : string ;
0 commit comments