@@ -19,7 +19,8 @@ import {
19
19
} from './fixtures/counter' ;
20
20
import Spy = jasmine . Spy ;
21
21
import any = jasmine . any ;
22
- import { take } from 'rxjs/operators' ;
22
+ import { skip , take } from 'rxjs/operators' ;
23
+ import { MockStore , provideMockStore } from '../testing' ;
23
24
24
25
interface TestAppSchema {
25
26
counter1 : number ;
@@ -432,4 +433,42 @@ describe('ngRx Store', () => {
432
433
} ;
433
434
}
434
435
} ) ;
436
+
437
+ describe ( 'Mock Store' , ( ) => {
438
+ let mockStore : MockStore < TestAppSchema > ;
439
+
440
+ beforeEach ( ( ) => {
441
+ const initialState = { counter1 : 0 , counter2 : 1 } ;
442
+
443
+ TestBed . configureTestingModule ( {
444
+ providers : [ provideMockStore ( { initialState } ) ] ,
445
+ } ) ;
446
+
447
+ mockStore = TestBed . get ( Store ) ;
448
+ } ) ;
449
+
450
+ it ( 'should set the initial state to a mocked one' , ( done : DoneFn ) => {
451
+ const fixedState = {
452
+ counter1 : 17 ,
453
+ counter2 : 11 ,
454
+ counter3 : 25 ,
455
+ } ;
456
+ mockStore . setState ( fixedState ) ;
457
+ mockStore . pipe ( take ( 1 ) ) . subscribe ( {
458
+ next ( val ) {
459
+ expect ( val ) . toEqual ( fixedState ) ;
460
+ } ,
461
+ error : done . fail ,
462
+ complete : done ,
463
+ } ) ;
464
+ } ) ;
465
+
466
+ it ( 'should allow tracing dispatched actions' , ( ) => {
467
+ const action = { type : INCREMENT } ;
468
+ mockStore . scannedActions$
469
+ . pipe ( skip ( 1 ) )
470
+ . subscribe ( scannedAction => expect ( scannedAction ) . toEqual ( action ) ) ;
471
+ mockStore . dispatch ( action ) ;
472
+ } ) ;
473
+ } ) ;
435
474
} ) ;
0 commit comments