forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocation_mock.ts
More file actions
46 lines (35 loc) · 1.27 KB
/
Copy pathlocation_mock.ts
File metadata and controls
46 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {Location} from 'angular2/src/router/location';
export class SpyLocation implements Location {
urlChanges: string[] = [];
_path: string = '';
_subject: EventEmitter = new EventEmitter();
_baseHref: string = '';
setInitialPath(url: string) { this._path = url; }
setBaseHref(url: string) { this._baseHref = url; }
path(): string { return this._path; }
simulateUrlPop(pathname: string) { ObservableWrapper.callNext(this._subject, {'url': pathname}); }
normalizeAbsolutely(url: string): string { return this._baseHref + url; }
go(url: string) {
url = this.normalizeAbsolutely(url);
if (this._path == url) {
return;
}
this._path = url;
this.urlChanges.push(url);
}
forward() {
// TODO
}
back() {
// TODO
}
subscribe(onNext: (value: any) => void, onThrow: (error: any) => void = null,
onReturn: () => void = null) {
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
}
// TODO: remove these once Location is an interface, and can be implemented cleanly
platformStrategy: any = null;
normalize(url: string): string { return null; }
}