Skip to content

Commit e8ea509

Browse files
committed
Additional test coverage for view handling, fixes #243.
1 parent 4fc388b commit e8ea509

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

test/stateSpec.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ describe('state', function () {
5757
templateParams = params;
5858
return "/templates/" + params.item + ".html";
5959
}
60-
});
60+
})
61+
62+
.state('first', { url: '^/first/subpath' })
63+
.state('second', { url: '^/second' });
6164

6265
$provide.value('AppInjectable', AppInjectable);
6366
}));
@@ -393,17 +396,37 @@ describe('state', function () {
393396
});
394397

395398
describe('url handling', function () {
396-
397399
it('should transition to the same state with different parameters', inject(function ($state, $rootScope, $location) {
398400
$location.path("/about/bob");
399401
$rootScope.$broadcast("$locationChangeSuccess");
400402
$rootScope.$apply();
401403
expect($state.params).toEqual({ person: "bob" });
404+
expect($state.current.name).toBe('about.person');
402405

403406
$location.path("/about/larry");
404407
$rootScope.$broadcast("$locationChangeSuccess");
405408
$rootScope.$apply();
406409
expect($state.params).toEqual({ person: "larry" });
410+
expect($state.current.name).toBe('about.person');
411+
}));
412+
413+
it('should correctly handle absolute urls', inject(function ($state, $rootScope, $location) {
414+
$location.path("/first/subpath");
415+
$rootScope.$broadcast("$locationChangeSuccess");
416+
$rootScope.$apply();
417+
expect($state.current.name).toBe('first');
418+
419+
$state.transitionTo('second');
420+
$rootScope.$apply();
421+
expect($state.current.name).toBe('second');
422+
expect($location.path()).toBe('/second');
423+
}));
424+
425+
it('should ignore bad urls', inject(function ($state, $rootScope, $location) {
426+
$location.path("/first/second");
427+
$rootScope.$broadcast("$locationChangeSuccess");
428+
$rootScope.$apply();
429+
expect($state.current.name).toBe('');
407430
}));
408431
});
409432

0 commit comments

Comments
 (0)