diff options
Diffstat (limited to 'test/ng/compileSpec.js')
| -rw-r--r-- | test/ng/compileSpec.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 74eaec8a..1c4a1d30 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -991,6 +991,33 @@ describe('$compile', function() { } }; }); + $compileProvider.directive('tscope' + uppercase(name), function(log) { + return { + scope: true, + restrict: 'CA', + templateUrl: 'tscope.html', + compile: function() { + return function (scope, element) { + log(scope.$id); + expect(element.data('$scope')).toBe(scope); + }; + } + }; + }); + $compileProvider.directive('trscope' + uppercase(name), function(log) { + return { + scope: true, + replace: true, + restrict: 'CA', + templateUrl: 'trscope.html', + compile: function() { + return function (scope, element) { + log(scope.$id); + expect(element.data('$scope')).toBe(scope); + }; + } + }; + }); $compileProvider.directive('tiscope' + uppercase(name), function(log) { return { scope: {}, @@ -1034,6 +1061,33 @@ describe('$compile', function() { })); + it('should allow creation of new scopes for directives with templates', inject( + function($rootScope, $compile, log, $httpBackend) { + $httpBackend.expect('GET', 'tscope.html').respond('<a log>{{name}}; scopeId: {{$id}}</a>'); + element = $compile('<div><span tscope></span></div>')($rootScope); + $httpBackend.flush(); + expect(log).toEqual('LOG; log-002-001; 002'); + $rootScope.name = 'Jozo'; + $rootScope.$apply(); + expect(element.text()).toBe('Jozo; scopeId: 002'); + expect(element.find('span').scope().$id).toBe('002'); + })); + + + it('should allow creation of new scopes for replace directives with templates', inject( + function($rootScope, $compile, log, $httpBackend) { + $httpBackend.expect('GET', 'trscope.html'). + respond('<p><a log>{{name}}; scopeId: {{$id}}</a></p>'); + element = $compile('<div><span trscope></span></div>')($rootScope); + $httpBackend.flush(); + expect(log).toEqual('LOG; log-002-001; 002'); + $rootScope.name = 'Jozo'; + $rootScope.$apply(); + expect(element.text()).toBe('Jozo; scopeId: 002'); + expect(element.find('a').scope().$id).toBe('002'); + })); + + it('should allow creation of new isolated scopes for directives with templates', inject( function($rootScope, $compile, log, $httpBackend) { $httpBackend.expect('GET', 'tiscope.html').respond('<a log></a>'); |
