@@ -232,27 +232,27 @@ than the hash fragment was changed.
232
232
### Example
233
233
234
234
```js
235
- it('should show example', inject(
236
- function($locationProvider) {
235
+ it('should show example', function() {
236
+ module( function($locationProvider) {
237
237
$locationProvider.html5Mode(false);
238
238
$locationProvider.hashPrefix('!');
239
- },
240
- function($location) {
239
+ });
240
+ inject( function($location) {
241
241
// 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');
244
244
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');
247
247
248
- $location.search() === {}
248
+ expect( $location.search()).toEqual({});
249
249
$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');
251
251
252
252
$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
+ } );
256
256
```
257
257
258
258
## HTML5 mode
@@ -274,40 +274,50 @@ and updates the url in a way that never performs a full page reload.
274
274
### Example
275
275
276
276
```js
277
- it('should show example', inject(
278
- function($locationProvider) {
277
+ it('should show example', function() {
278
+ module( function($locationProvider) {
279
279
$locationProvider.html5Mode(true);
280
280
$locationProvider.hashPrefix('!');
281
- },
282
- function($location) {
281
+ });
282
+ inject( function($location) {
283
283
// in browser with HTML5 history support:
284
284
// open http://example.com/#!/a -> rewrite to http://example.com/a
285
285
// (replacing the http://example.com/#!/a history record)
286
- $location.path() === '/a'
286
+ expect( $location.path()).toBe( '/a');
287
287
288
288
$location.path('/foo');
289
- $location.absUrl() === 'http://example.com/foo'
289
+ expect( $location.absUrl()).toBe( 'http://example.com/foo');
290
290
291
- $location.search() === {}
291
+ expect( $location.search()).toEqual({});
292
292
$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');
294
294
295
295
$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
+ });
298
300
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) {
299
309
// in browser without html5 history support:
300
310
// open http://example.com/new?x=y -> redirect to http://example.com/#!/new?x=y
301
311
// (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'});
304
314
305
315
$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
+ } );
311
321
```
312
322
313
323
### Fallback for legacy browsers
0 commit comments