@@ -19,7 +19,8 @@ import {
1919} from './fixtures/counter' ;
2020import Spy = jasmine . Spy ;
2121import any = jasmine . any ;
22- import { take } from 'rxjs/operators' ;
22+ import { skip , take } from 'rxjs/operators' ;
23+ import { MockStore , provideMockStore } from '../testing' ;
2324
2425interface TestAppSchema {
2526 counter1 : number ;
@@ -432,4 +433,42 @@ describe('ngRx Store', () => {
432433 } ;
433434 }
434435 } ) ;
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+ } ) ;
435474} ) ;
0 commit comments