"Fossies" - the Fresh Open Source Software Archive

Member "angular-8.2.14/aio/content/examples/testing/src/testing/activated-route-stub.ts" (13 Nov 2019, 921 Bytes) of package /linux/www/angular-8.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // export for convenience.
    2 export { ActivatedRoute } from '@angular/router';
    3 
    4 // #docregion activated-route-stub
    5 import { convertToParamMap, ParamMap, Params } from '@angular/router';
    6 import { ReplaySubject } from 'rxjs';
    7 
    8 /**
    9  * An ActivateRoute test double with a `paramMap` observable.
   10  * Use the `setParamMap()` method to add the next `paramMap` value.
   11  */
   12 export class ActivatedRouteStub {
   13   // Use a ReplaySubject to share previous values with subscribers
   14   // and pump new values into the `paramMap` observable
   15   private subject = new ReplaySubject<ParamMap>();
   16 
   17   constructor(initialParams?: Params) {
   18     this.setParamMap(initialParams);
   19   }
   20 
   21   /** The mock paramMap observable */
   22   readonly paramMap = this.subject.asObservable();
   23 
   24   /** Set the paramMap observables's next value */
   25   setParamMap(params?: Params) {
   26     this.subject.next(convertToParamMap(params));
   27   };
   28 }
   29 // #enddocregion activated-route-stub