diff options
| author | Igor Minar | 2013-11-07 16:19:03 -0800 | 
|---|---|---|
| committer | Igor Minar | 2013-11-07 22:08:22 -0800 | 
| commit | 27e9340b3c25b512e45213b39811098d07e12e3b (patch) | |
| tree | 63f817a20eea62f813fcf85ad40c1b8bcc6e1652 /test/ng/compileSpec.js | |
| parent | b5af198f0d5b0f2b3ddb31ea12f700f3e0616271 (diff) | |
| download | angular.js-27e9340b3c25b512e45213b39811098d07e12e3b.tar.bz2 | |
feat(jqLite): expose isolateScope() getter similar to scope()
See doc update in the diff for more info.
BREAKING CHANGE: jqLite#scope() does not return the isolate scope on the element
that triggered directive with isolate scope. Use jqLite#isolateScope() instead.
Diffstat (limited to 'test/ng/compileSpec.js')
| -rwxr-xr-x | test/ng/compileSpec.js | 120 | 
1 files changed, 118 insertions, 2 deletions
| diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index a61d50f2..5bdbad42 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1375,7 +1375,7 @@ describe('$compile', function() {                    return function (scope, element) {                      iscope = scope;                      log(scope.$id); -                    expect(element.data('$isolateScope')).toBe(scope); +                    expect(element.data('$isolateScopeNoTemplate')).toBe(scope);                    };                  }                }; @@ -1522,7 +1522,7 @@ describe('$compile', function() {          ); -        it('should allow more one new scope directives per element, but directives should share' + +        it('should allow more than one new scope directives per element, but directives should share' +              'the scope', inject(            function($rootScope, $compile, log) {              element = $compile('<div class="scope-a; scope-b"></div>')($rootScope); @@ -1554,6 +1554,120 @@ describe('$compile', function() {              expect(log).toEqual('002');            })          ); + + +        describe('scope()/isolate() scope getters', function() { + +          describe('with no directives', function() { + +            it('should return the scope of the parent node', inject( +              function($rootScope, $compile) { +                element = $compile('<div></div>')($rootScope); +                expect(element.scope()).toBe($rootScope); +              }) +            ); +          }); + + +          describe('with new scope directives', function() { + +            it('should return the new scope at the directive element', inject( +              function($rootScope, $compile) { +                element = $compile('<div scope></div>')($rootScope); +                expect(element.scope().$parent).toBe($rootScope); +              }) +            ); + + +            it('should return the new scope for children in the original template', inject( +              function($rootScope, $compile) { +                element = $compile('<div scope><a></a></div>')($rootScope); +                expect(element.find('a').scope().$parent).toBe($rootScope); +              }) +            ); + + +            it('should return the new scope for children in the directive template', inject( +              function($rootScope, $compile, $httpBackend) { +                $httpBackend.expect('GET', 'tscope.html').respond('<a></a>'); +                element = $compile('<div tscope></div>')($rootScope); +                $httpBackend.flush(); +                expect(element.find('a').scope().$parent).toBe($rootScope); +              }) +            ); +          }); + + +          describe('with isolate scope directives', function() { + +            it('should return the root scope for directives at the root element', inject( +              function($rootScope, $compile) { +                element = $compile('<div iscope></div>')($rootScope); +                expect(element.scope()).toBe($rootScope); +              }) +            ); + + +            it('should return the non-isolate scope at the directive element', inject( +              function($rootScope, $compile) { +                var directiveElement; +                element = $compile('<div><div iscope></div></div>')($rootScope); +                directiveElement = element.children(); +                expect(directiveElement.scope()).toBe($rootScope); +                expect(directiveElement.isolateScope().$parent).toBe($rootScope); +              }) +            ); + + +            it('should return the isolate scope for children in the original template', inject( +              function($rootScope, $compile) { +                element = $compile('<div iscope><a></a></div>')($rootScope); +                expect(element.find('a').scope()).toBe($rootScope); //xx +              }) +            ); + + +            it('should return the isolate scope for children in directive template', inject( +              function($rootScope, $compile, $httpBackend) { +                $httpBackend.expect('GET', 'tiscope.html').respond('<a></a>'); +                element = $compile('<div tiscope></div>')($rootScope); +                expect(element.isolateScope()).toBeUndefined(); // this is the current behavior, not desired feature +                $httpBackend.flush(); +                expect(element.find('a').scope()).toBe(element.isolateScope()); +                expect(element.isolateScope()).not.toBe($rootScope); +              }) +            ); +          }); + + +          describe('with isolate scope directives and directives that manually create a new scope', function() { + +            it('should return the new scope at the directive element', inject( +              function($rootScope, $compile) { +                var directiveElement; +                element = $compile('<div><a ng-if="true" iscope></a></div>')($rootScope); +                $rootScope.$apply(); +                directiveElement = element.find('a'); +                expect(directiveElement.scope().$parent).toBe($rootScope); +                expect(directiveElement.scope()).not.toBe(directiveElement.isolateScope()); +              }) +            ); + + +            it('should return the isolate scope for child elements', inject( +              function($rootScope, $compile, $httpBackend) { +                var directiveElement, child; +                $httpBackend.expect('GET', 'tiscope.html').respond('<span></span>'); +                element = $compile('<div><a ng-if="true" tiscope></a></div>')($rootScope); +                $rootScope.$apply(); +                $httpBackend.flush(); +                directiveElement = element.find('a'); +                child = directiveElement.find('span'); +                expect(child.scope()).toBe(directiveElement.isolateScope()); +              }) +            ); +          }); +        });        });      });    }); @@ -2121,6 +2235,7 @@ describe('$compile', function() {        });      })); +      it('should give other directives the parent scope', inject(function($rootScope) {        compile('<div><input type="text" my-component store-scope ng-model="value"></div>');        $rootScope.$apply(function() { @@ -2131,6 +2246,7 @@ describe('$compile', function() {        expect(componentScope.$parent).toBe(regularScope)      })); +      it('should not give the isolate scope to other directive template', function() {        module(function() {          directive('otherTplDir', function() { | 
