Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1e3c7d2

Browse files
mgolpetebacondarwin
authored andcommitted
docs($location): fix examples
The examples contained tests with assertions in form of regular equality comparisons which would be noops and in case of an error nothing would get reported. Also, one of the test mixed a HTML5 browser scenario with a non-HTML5 one.
1 parent 187fce7 commit 1e3c7d2

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

docs/content/guide/$location.ngdoc

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,27 @@ than the hash fragment was changed.
232232
### Example
233233

234234
```js
235-
it('should show example', inject(
236-
function($locationProvider) {
235+
it('should show example', function() {
236+
module(function($locationProvider) {
237237
$locationProvider.html5Mode(false);
238238
$locationProvider.hashPrefix('!');
239-
},
240-
function($location) {
239+
});
240+
inject(function($location) {
241241
// open http://example.com/base/index.html#!/a
242-
$location.absUrl() === 'http://example.com/base/index.html#!/a'
243-
$location.path() === '/a'
242+
expect($location.absUrl()).toBe('http://example.com/base/index.html#!/a');
243+
expect($location.path()).toBe('/a');
244244

245-
$location.path('/foo')
246-
$location.absUrl() === 'http://example.com/base/index.html#!/foo'
245+
$location.path('/foo');
246+
expect($location.absUrl()).toBe('http://example.com/base/index.html#!/foo');
247247

248-
$location.search() === {}
248+
expect($location.search()).toEqual({});
249249
$location.search({a: 'b', c: true});
250-
$location.absUrl() === 'http://example.com/base/index.html#!/foo?a=b&c'
250+
expect($location.absUrl()).toBe('http://example.com/base/index.html#!/foo?a=b&c');
251251

252252
$location.path('/new').search('x=y');
253-
$location.absUrl() === 'http://example.com/base/index.html#!/new?x=y'
254-
}
255-
));
253+
expect($location.absUrl()).toBe('http://example.com/base/index.html#!/new?x=y');
254+
});
255+
});
256256
```
257257

258258
## HTML5 mode
@@ -274,40 +274,50 @@ and updates the url in a way that never performs a full page reload.
274274
### Example
275275

276276
```js
277-
it('should show example', inject(
278-
function($locationProvider) {
277+
it('should show example', function() {
278+
module(function($locationProvider) {
279279
$locationProvider.html5Mode(true);
280280
$locationProvider.hashPrefix('!');
281-
},
282-
function($location) {
281+
});
282+
inject(function($location) {
283283
// in browser with HTML5 history support:
284284
// open http://example.com/#!/a -> rewrite to http://example.com/a
285285
// (replacing the http://example.com/#!/a history record)
286-
$location.path() === '/a'
286+
expect($location.path()).toBe('/a');
287287

288288
$location.path('/foo');
289-
$location.absUrl() === 'http://example.com/foo'
289+
expect($location.absUrl()).toBe('http://example.com/foo');
290290

291-
$location.search() === {}
291+
expect($location.search()).toEqual({});
292292
$location.search({a: 'b', c: true});
293-
$location.absUrl() === 'http://example.com/foo?a=b&c'
293+
expect($location.absUrl()).toBe('http://example.com/foo?a=b&c');
294294

295295
$location.path('/new').search('x=y');
296-
$location.url() === 'new?x=y'
297-
$location.absUrl() === 'http://example.com/new?x=y'
296+
expect($location.url()).toBe('/new?x=y');
297+
expect($location.absUrl()).toBe('http://example.com/new?x=y');
298+
});
299+
});
298300

301+
it('should show example (when browser doesn\'t support HTML5 mode', function() {
302+
module(function($provide, $locationProvider) {
303+
$locationProvider.html5Mode(true);
304+
$locationProvider.hashPrefix('!');
305+
$provide.value('$sniffer', {history: false});
306+
});
307+
inject(initBrowser({ url: 'http://example.com/new?x=y', basePath: '/' }),
308+
function($location) {
299309
// in browser without html5 history support:
300310
// open http://example.com/new?x=y -> redirect to http://example.com/#!/new?x=y
301311
// (again replacing the http://example.com/new?x=y history item)
302-
$location.path() === '/new'
303-
$location.search() === {x: 'y'}
312+
expect($location.path()).toBe('/new');
313+
expect($location.search()).toEqual({x: 'y'});
304314

305315
$location.path('/foo/bar');
306-
$location.path() === '/foo/bar'
307-
$location.url() === '/foo/bar?x=y'
308-
$location.absUrl() === 'http://example.com/#!/foo/bar?x=y'
309-
}
310-
));
316+
expect($location.path()).toBe('/foo/bar');
317+
expect($location.url()).toBe('/foo/bar?x=y');
318+
expect($location.absUrl()).toBe('http://example.com/#!/foo/bar?x=y');
319+
});
320+
});
311321
```
312322

313323
### Fallback for legacy browsers

0 commit comments

Comments
 (0)