src/app/tests/mocks/activated-route.ts
Mock for angular ActivatedRoute.
If logic for getting or subscribing to parameters is as: this.sub = this.route.params.subscribe(params => { this.id = params['id']; });
Create mock and set params as shown below: const activeRoute = new MockActivatedRoute(); activeRoute.testParams = { id: 'myparamid' };
Properties |
|
Accessors |
Private _testParams |
_testParams:
|
Type : literal type
|
Defined in src/app/tests/mocks/activated-route.ts:18
|
params |
params:
|
Defined in src/app/tests/mocks/activated-route.ts:20
|
parent |
parent:
|
Defined in src/app/tests/mocks/activated-route.ts:22
|
snapshot |
snapshot:
|
Defined in src/app/tests/mocks/activated-route.ts:21
|
Private subject |
subject:
|
Defined in src/app/tests/mocks/activated-route.ts:19
|
testParams | ||||||||
gettestParams()
|
||||||||
Defined in src/app/tests/mocks/activated-route.ts:26
|
||||||||
settestParams(testParams: any)
|
||||||||
Defined in src/app/tests/mocks/activated-route.ts:30
|
||||||||
Parameters :
Returns :
void
|
import { BehaviorSubject } from 'rxjs';
/**
* Mock for angular ActivatedRoute.
*
* If logic for getting or subscribing to parameters is as:
* this.sub = this.route.params.subscribe(params => {
* this.id = params['id'];
* });
*
* Create mock and set params as shown below:
* const activeRoute = new MockActivatedRoute();
* activeRoute.testParams = { id: 'myparamid' };
*
* @author Janne Valkealahti
*/
export class MockActivatedRoute {
private _testParams: {};
private subject = new BehaviorSubject(this.testParams);
params = this.subject.asObservable();
snapshot = {};
parent = {
params: this.subject.asObservable()
};
get testParams() {
return this._testParams;
}
set testParams(testParams: any) {
this._testParams = testParams;
this.subject.next(testParams);
}
}