From faf02f0c4db7962f863b0da2a82c8cafab2c706f Mon Sep 17 00:00:00 2001 From: Luis Ramón López Date: Sat, 3 Nov 2012 21:11:07 +0100 Subject: feat(route): Allow using functions as template params in 'when' --- test/ng/routeSpec.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test/ng/routeSpec.js') 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 '

' + routePathParams.id + '

'; + } + + 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() { -- cgit v1.2.3