Skip to content

Commit 3b64d38

Browse files
author
Anatoly Ostrovsky
committed
Fix tests
1 parent b6c7900 commit 3b64d38

File tree

3 files changed

+53
-95
lines changed

3 files changed

+53
-95
lines changed

src/router/directives/state-directives.spec.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,37 @@ describe("ngStateRef", () => {
2222
window.location.hash = "";
2323
window.angular = new Angular();
2424
let module = window.angular.module("defaultModule", []);
25-
module.config(($stateProvider, $locationProvider) => {
26-
_locationProvider = $locationProvider;
27-
$locationProvider.hashPrefix("");
28-
$stateProvider
29-
.state({ name: "top", url: "" })
30-
.state({ name: "other", url: "/other/:id", template: "other" })
31-
.state({ name: "other.detail", url: "/detail", template: "detail" })
32-
.state({
33-
name: "contacts",
34-
url: "/contacts",
35-
template:
36-
'<a ng-sref=".item({ id: 5 })" class="item">Person</a> <ng-view></ng-view>',
37-
})
38-
.state({
39-
name: "contacts.item",
40-
url: "/{id:int}",
41-
template:
42-
'<a ng-sref=".detail" class="item-detail">Detail</a> | <a ng-sref="^" class="item-parent">Parent</a> | <ng-view></ng-view>',
43-
})
44-
.state({
45-
name: "contacts.item.detail",
46-
template:
47-
'<div class="title">Detail</div> | <a ng-sref="^" class="item-parent2">Item</a>',
48-
});
49-
});
25+
module.config(
26+
/**
27+
* @param $stateProvider
28+
* @param {import('../../core/location/location.js').LocationProvider} $locationProvider
29+
*/
30+
($stateProvider, $locationProvider) => {
31+
_locationProvider = $locationProvider;
32+
$locationProvider.setHashPrefix("");
33+
$stateProvider
34+
.state({ name: "top", url: "" })
35+
.state({ name: "other", url: "/other/:id", template: "other" })
36+
.state({ name: "other.detail", url: "/detail", template: "detail" })
37+
.state({
38+
name: "contacts",
39+
url: "/contacts",
40+
template:
41+
'<a ng-sref=".item({ id: 5 })" class="item">Person</a> <ng-view></ng-view>',
42+
})
43+
.state({
44+
name: "contacts.item",
45+
url: "/{id:int}",
46+
template:
47+
'<a ng-sref=".detail" class="item-detail">Detail</a> | <a ng-sref="^" class="item-parent">Parent</a> | <ng-view></ng-view>',
48+
})
49+
.state({
50+
name: "contacts.item.detail",
51+
template:
52+
'<div class="title">Detail</div> | <a ng-sref="^" class="item-parent2">Item</a>',
53+
});
54+
},
55+
);
5056
$injector = window.angular.bootstrap(document.getElementById("dummy"), [
5157
"defaultModule",
5258
]);

src/router/url/url-service.js

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class UrlService {
2121

2222
/**
2323
* @param {import("../../core/location/location").LocationProvider} $locationProvider
24+
* @param {import("../../router/state/state-service.js").StateProvider} stateService
25+
* @param globals
26+
* @param {import("../../router/url/url-config.js").UrlConfigProvider} urlConfigProvider
2427
*/
2528
constructor($locationProvider, stateService, globals, urlConfigProvider) {
2629
this.stateService = stateService;
@@ -30,9 +33,6 @@ export class UrlService {
3033
this.$location = undefined;
3134
this.$browser = undefined;
3235

33-
/** @type {boolean} */
34-
this.interceptDeferred = false;
35-
3636
/** Provides services related to the URL */
3737
this.urlRuleFactory = new UrlRuleFactory(this, this.stateService, globals);
3838

@@ -91,7 +91,7 @@ export class UrlService {
9191
* @param {import('../../core/location/location').Location} $location
9292
* @param {import('../../services/browser').Browser} $browser
9393
* @param {import('../../core/scope/scope').Scope} $rootScope
94-
* @returns
94+
* @returns {UrlService}
9595
*/
9696
($location, $browser, $rootScope) => {
9797
this.$location = $location;
@@ -104,10 +104,14 @@ export class UrlService {
104104
},
105105
];
106106

107+
/**
108+
* @returns {boolean}
109+
*/
107110
html5Mode() {
108-
let html5Mode = this.$locationProvider.html5Mode();
109-
html5Mode = isObject(html5Mode) ? html5Mode.enabled : html5Mode;
110-
return html5Mode && typeof history !== "undefined";
111+
return (
112+
this.$locationProvider.getHtml5Mode().enabled &&
113+
typeof history !== "undefined"
114+
);
111115
}
112116

113117
baseHref() {
@@ -214,7 +218,6 @@ export class UrlService {
214218
*
215219
* #### Example:
216220
* ```js
217-
* urlService.deferIntercept();
218221
*
219222
* fetch('/states.json').then(resp => resp.json()).then(data => {
220223
* data.forEach(state => $stateRegistry.register(state));
@@ -261,7 +264,6 @@ export class UrlService {
261264
*
262265
* #### Example:
263266
* ```js
264-
* urlService.deferIntercept();
265267
*
266268
* fetch('/states.json').then(resp => resp.json()).then(data => {
267269
* data.forEach(state => $stateRegistry.register(state));
@@ -282,34 +284,7 @@ export class UrlService {
282284
this._stopListeningFn || this.onChange((evt) => this.sync(evt)));
283285
}
284286
}
285-
/**
286-
* Disables monitoring of the URL.
287-
*
288-
* Call this method before ng-router has bootstrapped.
289-
* It will stop ng-router from performing the initial url sync.
290-
*
291-
* This can be useful to perform some asynchronous initialization before the router starts.
292-
* Once the initialization is complete, call [[listen]] to tell ng-router to start watching and synchronizing the URL.
293-
*
294-
* #### Example:
295-
* ```js
296-
* // Prevent ng-router from automatically intercepting URL changes when it starts;
297-
* urlService.deferIntercept();
298-
*
299-
* fetch('/states.json').then(resp => resp.json()).then(data => {
300-
* data.forEach(state => $stateRegistry.register(state));
301-
* urlService.listen();
302-
* urlService.sync();
303-
* });
304-
* ```
305-
*
306-
* @param defer Indicates whether to defer location change interception.
307-
* Passing no parameter is equivalent to `true`.
308-
*/
309-
deferIntercept(defer) {
310-
if (defer === undefined) defer = true;
311-
this.interceptDeferred = defer;
312-
}
287+
313288
/**
314289
* Matches a URL
315290
*
@@ -394,7 +369,7 @@ export class UrlService {
394369
options = options || { absolute: false };
395370
const isHtml5 = this.html5Mode();
396371
if (!isHtml5 && url !== null) {
397-
url = "#" + this.$locationProvider.hashPrefix() + url;
372+
url = "#" + this.$locationProvider.getHashPrefix() + url;
398373
}
399374
url = appendBasePath(url, isHtml5, options.absolute, this.baseHref());
400375
if (!options.absolute || !url) {

types/router/url/url-service.d.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ export class UrlService {
55
static $inject: string[];
66
/**
77
* @param {import("../../core/location/location").LocationProvider} $locationProvider
8+
* @param {import("../../router/state/state-service.js").StateProvider} stateService
9+
* @param globals
10+
* @param {import("../../router/url/url-config.js").UrlConfigProvider} urlConfigProvider
811
*/
9-
constructor($locationProvider: import("../../core/location/location").LocationProvider, stateService: any, globals: any, urlConfigProvider: any);
10-
stateService: any;
12+
constructor($locationProvider: import("../../core/location/location").LocationProvider, stateService: import("../../router/state/state-service.js").StateProvider, globals: any, urlConfigProvider: import("../../router/url/url-config.js").UrlConfigProvider);
13+
stateService: import("../../router/state/state-service.js").StateProvider;
1114
$locationProvider: import("../../core/location/location").LocationProvider;
1215
$location: import("../../core/location/location").Location;
1316
$browser: import("../../services/browser").Browser;
14-
/** @type {boolean} */
15-
interceptDeferred: boolean;
1617
/** Provides services related to the URL */
1718
urlRuleFactory: UrlRuleFactory;
1819
/**
@@ -56,7 +57,10 @@ export class UrlService {
5657
*/
5758
hash: () => string | import("../../core/location/location").Location;
5859
_urlListeners: any[];
59-
$get: (string | (($location: import("../../core/location/location").Location, $browser: import("../../services/browser").Browser, $rootScope: import("../../core/scope/scope").Scope) => this))[];
60+
$get: (string | (($location: import("../../core/location/location").Location, $browser: import("../../services/browser").Browser, $rootScope: import("../../core/scope/scope").Scope) => UrlService))[];
61+
/**
62+
* @returns {boolean}
63+
*/
6064
html5Mode(): boolean;
6165
baseHref(): string;
6266
_baseHref: string;
@@ -149,7 +153,6 @@ export class UrlService {
149153
*
150154
* #### Example:
151155
* ```js
152-
* urlService.deferIntercept();
153156
*
154157
* fetch('/states.json').then(resp => resp.json()).then(data => {
155158
* data.forEach(state => $stateRegistry.register(state));
@@ -170,7 +173,6 @@ export class UrlService {
170173
*
171174
* #### Example:
172175
* ```js
173-
* urlService.deferIntercept();
174176
*
175177
* fetch('/states.json').then(resp => resp.json()).then(data => {
176178
* data.forEach(state => $stateRegistry.register(state));
@@ -184,31 +186,6 @@ export class UrlService {
184186
*/
185187
listen(enabled: any): any;
186188
_stopListeningFn: any;
187-
/**
188-
* Disables monitoring of the URL.
189-
*
190-
* Call this method before ng-router has bootstrapped.
191-
* It will stop ng-router from performing the initial url sync.
192-
*
193-
* This can be useful to perform some asynchronous initialization before the router starts.
194-
* Once the initialization is complete, call [[listen]] to tell ng-router to start watching and synchronizing the URL.
195-
*
196-
* #### Example:
197-
* ```js
198-
* // Prevent ng-router from automatically intercepting URL changes when it starts;
199-
* urlService.deferIntercept();
200-
*
201-
* fetch('/states.json').then(resp => resp.json()).then(data => {
202-
* data.forEach(state => $stateRegistry.register(state));
203-
* urlService.listen();
204-
* urlService.sync();
205-
* });
206-
* ```
207-
*
208-
* @param defer Indicates whether to defer location change interception.
209-
* Passing no parameter is equivalent to `true`.
210-
*/
211-
deferIntercept(defer: any): void;
212189
/**
213190
* Matches a URL
214191
*

0 commit comments

Comments
 (0)