aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuis Ramón López2012-11-03 21:11:07 +0100
committerMisko Hevery2013-01-18 21:20:49 -0800
commitfaf02f0c4db7962f863b0da2a82c8cafab2c706f (patch)
tree9602f0d265d47ee0018a03654cee0f68b1c83488 /test
parentb8bd4d5460d9952e9a3bb14992636b17859bd457 (diff)
downloadangular.js-faf02f0c4db7962f863b0da2a82c8cafab2c706f.tar.bz2
feat(route): Allow using functions as template params in 'when'
Diffstat (limited to 'test')
-rw-r--r--test/ng/routeSpec.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js
index 852f97b5..e8e63b77 100644
--- a/test/ng/routeSpec.js
+++ b/test/ng/routeSpec.js
@@ -715,6 +715,53 @@ describe('$route', function() {
});
+ it('should allow using a function as a template', function() {
+ var customTemplateWatcher = jasmine.createSpy('customTemplateWatcher');
+
+ function customTemplateFn(routePathParams) {
+ customTemplateWatcher(routePathParams);
+ expect(routePathParams).toEqual({id: 'id3'});
+ return '<h1>' + routePathParams.id + '</h1>';
+ }
+
+ module(function($routeProvider){
+ $routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
+ $routeProvider.when('/foo/:id', {template: customTemplateFn});
+ });
+
+ inject(function($route, $location, $rootScope) {
+ $location.path('/foo/id3');
+ $rootScope.$digest();
+
+ expect(customTemplateWatcher).toHaveBeenCalledWith({id: 'id3'});
+ });
+ });
+
+
+ it('should allow using a function as a templateUrl', function() {
+ var customTemplateUrlWatcher = jasmine.createSpy('customTemplateUrlWatcher');
+
+ function customTemplateUrlFn(routePathParams) {
+ customTemplateUrlWatcher(routePathParams);
+ expect(routePathParams).toEqual({id: 'id3'});
+ return 'foo.html';
+ }
+
+ module(function($routeProvider){
+ $routeProvider.when('/bar/:id/:subid/:subsubid', {templateUrl: 'bar.html'});
+ $routeProvider.when('/foo/:id', {templateUrl: customTemplateUrlFn});
+ });
+
+ inject(function($route, $location, $rootScope) {
+ $location.path('/foo/id3');
+ $rootScope.$digest();
+
+ expect(customTemplateUrlWatcher).toHaveBeenCalledWith({id: 'id3'});
+ expect($route.current.loadedTemplateUrl).toEqual('foo.html');
+ });
+ });
+
+
describe('reload', function() {
it('should reload even if reloadOnSearch is false', function() {