SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Action, ActionReducer, Store } from '@ngrx/store';
  2. import { BehaviorSubject } from 'rxjs/BehaviorSubject';
  3. import { Observable } from 'rxjs/Observable';
  4. import { map } from 'rxjs/operator/map';
  5. import { Observer } from 'rxjs/Observer';
  6.  
  7. // TODO: How to initialize those variables?
  8. const dispatcherMock: Observer<Action>,
  9.     reducerMock: Observer<ActionReducer<any>>,
  10.     stateMock: Observable<any>;
  11.  
  12. export class MockStore<T> extends Store<T> {
  13.  
  14.     private _fakeData: Object = {};
  15.     private fakeDataSubject: BehaviorSubject<Object> = new BehaviorSubject(this._fakeData);
  16.  
  17.     select = <T, R>(mapFn: any, ...paths: string[]): Observable<R> => {
  18.         return map.call(this.fakeDataSubject, mapFn);
  19.     };
  20.  
  21.     constructor() {
  22.         super(dispatcherMock, reducerMock, stateMock);
  23.     }
  24.  
  25.     nextMock(mock: Object, ...keys: string[]) {
  26.         let curMockLevel = this._fakeData = {};
  27.         keys.forEach((key, idx) => {
  28.             curMockLevel = curMockLevel[key] = idx === keys.length - 1 ? mock : {};
  29.         });
  30.         this.fakeDataSubject.next(this._fakeData);
  31.     }
  32.  
  33.     get fakeData() {
  34.         return this._fakeData;
  35.     }
  36.  
  37. }
RAW Paste Data
Top