import { MemoizedSelector , Store } from '@ngrx/store' ; import { MemoizedSelectorWithProps } from '@ngrx/store/src/selector' ; import { BehaviorSubject , Observable , of } from 'rxjs' ; declare var jest ; declare type UnifiedSelector < T = any , Result = any > = MemoizedSelector < T , Result > | MemoizedSelectorWithProps < T , any , Result > ; export class StoreStub < StateType = any > extends BehaviorSubject < StateType > { static provider = { provide : Store , useValue : new StoreStub ( ) } ; public dispatch = jest . fn ( ) ; public select = jest . fn ( this . executeSelector ) ; private selectors : Map < UnifiedSelector , any > = new Map ( ) ; constructor ( initialState = null , private defaultReturn = null ) { super ( initialState ) ; } overrideSelector ( selector , value ) { this . selectors . set ( selector , value ) ; } executeSelector ( selector ) { const value = this . selectors . get ( selector ) || this . defaultReturn ; return value instanceof Observable ? value : of ( value ) ; } setState ( state ) { this . next ( state ) ; } setDefaultReturn ( value ) { this . defaultReturn = value ; } }