Skip to content

Instantly share code, notes, and snippets.

@fivunlm
Created August 18, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fivunlm/cabbbd3549ade0d025952c59660604c8 to your computer and use it in GitHub Desktop.
Save fivunlm/cabbbd3549ade0d025952c59660604c8 to your computer and use it in GitHub Desktop.
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