Created
August 18, 2017 14:54
-
-
Save fivunlm/cabbbd3549ade0d025952c59660604c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | |
import {Component, Directive, Injectable, Input, NgModule} from '@angular/core' | |
import {Subject, Subscriber} from "rxjs"; | |
import {NavigationStart} from "@angular/router"; | |
@Injectable() | |
export class ActivatedRouteStub { | |
// ActivatedRoute.params is Observable | |
private paramsSubject = new BehaviorSubject(this.testParams); | |
// Test parameters | |
private _testParams: {}; | |
get testParams() { return this._testParams; } | |
set testParams(params: {}) { | |
this._testParams = params; | |
this.paramsSubject.next(params); | |
} | |
// ActivatedRoute.queryParams is Observable | |
private queryParamsSubject = new BehaviorSubject(this.testQueryParams); | |
// Test parameters | |
private _testQueryParams: {}; | |
get testQueryParams() { return this._testQueryParams; } | |
set testQueryParams(params: {}) { | |
this._testQueryParams = params; | |
this.queryParamsSubject.next(params); | |
} | |
// ActivatedRoute.snapshot.params | |
get snapshot() { | |
return { params: this.testParams, queryParams: this.testQueryParams }; | |
} | |
} | |
@Injectable() | |
export class RouterStub { | |
events: Subject<any> = new Subject(); | |
navigateByUrl(url: string) { | |
this.events.next(new NavigationStart(1, url)); | |
} | |
navigate(commands: any[]){ | |
} | |
} | |
@Directive({ | |
selector: '[routerLink]', | |
host: { | |
'(click)': 'onClick()' | |
} | |
}) | |
export class RouterLinkStubDirective { | |
@Input('routerLink') linkParams: any; | |
navigatedTo: any = null; | |
onClick() { | |
this.navigatedTo = this.linkParams; | |
} | |
} | |
@Directive({ | |
selector: '[queryParams]', | |
}) | |
export class QueryParamsStubDirective { | |
@Input('queryParams') queryParams: any; | |
} | |
@Component({ | |
selector: 'router-outlet', | |
template: '<span></span>', | |
}) | |
export class RouterOutletStubComponent { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment