diff options
Diffstat (limited to 'test')
| -rwxr-xr-x | test/ng/compileSpec.js | 84 | ||||
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 37 | 
2 files changed, 109 insertions, 12 deletions
| diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 1e6f6e26..9a69824a 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1042,10 +1042,12 @@ describe('$compile', function() {                templateUrl: 'template.html'              }));            }); -          inject(function($compile){ +          inject(function($compile, $httpBackend){ +            $httpBackend.whenGET('template.html').respond('<p>template.html</p>');              expect(function() {                $compile('<div><div class="sync async"></div></div>'); -            }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [sync, async] asking for template on: '+ +              $httpBackend.flush(); +            }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [async, sync] asking for template on: '+                  '<div class="sync async">');            });          }); @@ -1205,7 +1207,7 @@ describe('$compile', function() {          )); -        it('should work when directive is a repeater', inject( +        it('should work when directive is in a repeater', inject(            function($compile, $httpBackend, $rootScope) {              $httpBackend.expect('GET', 'hello.html').                  respond('<span>i=<span ng-transclude></span>;</span>'); @@ -1317,7 +1319,7 @@ describe('$compile', function() {        }); -      describe('template as function', function() { +      describe('templateUrl as function', function() {          beforeEach(module(function() {            directive('myDirective', valueFn({ @@ -2745,23 +2747,81 @@ describe('$compile', function() {      }); -    it('should only allow one transclude per element', function() { +    it('should only allow one content transclusion per element', function() {        module(function() {          directive('first', valueFn({ -          scope: {}, -          restrict: 'CA', -          transclude: 'content' +          transclude: true          }));          directive('second', valueFn({ -          restrict: 'CA', -          transclude: 'content' +          transclude: true          }));        });        inject(function($compile) {          expect(function() { -          $compile('<div class="first second"></div>'); +          $compile('<div first="" second=""></div>'); +        }).toThrowMinErr('$compile', 'multidir', /Multiple directives \[first, second\] asking for transclusion on: <div .+/); +      }); +    }); + + +    it('should only allow one element transclusion per element', function() { +      module(function() { +        directive('first', valueFn({ +          transclude: 'element' +        })); +        directive('second', valueFn({ +          transclude: 'element' +        })); +      }); +      inject(function($compile) { +        expect(function() { +          $compile('<div first second></div>');          }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [first, second] asking for transclusion on: ' + -            '<div class="first second ng-isolate-scope ng-scope">'); +                '<!-- first:  -->'); +      }); +    }); + + +    it('should only allow one element transclusion per element when directives have different priorities', function() { +      // we restart compilation in this case and we need to remember the duplicates during the second compile +      // regression #3893 +      module(function() { +        directive('first', valueFn({ +          transclude: 'element', +          priority: 100 +        })); +        directive('second', valueFn({ +          transclude: 'element' +        })); +      }); +      inject(function($compile) { +        expect(function() { +          $compile('<div first second></div>'); +        }).toThrowMinErr('$compile', 'multidir', /Multiple directives \[first, second\] asking for transclusion on: <div .+/); +      }); +    }); + + +    it('should only allow one element transclusion per element when async replace directive is in the mix', function() { +      module(function() { +        directive('template', valueFn({ +          templateUrl: 'template.html', +          replace: true +        })); +        directive('first', valueFn({ +          transclude: 'element', +          priority: 100 +        })); +        directive('second', valueFn({ +          transclude: 'element' +        })); +      }); +      inject(function($compile, $httpBackend) { +        $httpBackend.expectGET('template.html').respond('<p second>template.html</p>'); +        $compile('<div template first></div>'); +        expect(function() { +          $httpBackend.flush(); +        }).toThrowMinErr('$compile', 'multidir', /Multiple directives \[first, second\] asking for transclusion on: <p .+/);        });      }); diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 8dba13bf..9dde36e7 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -976,6 +976,43 @@ describe('ngRepeat', function() {    }); +  describe('compatibility', function() { + +    it('should allow mixing ngRepeat and another element transclusion directive', function() { +      $compileProvider.directive('elmTrans', valueFn({ +        transclude: 'element', +        controller: function($transclude, $scope, $element) { +          $transclude(function(transcludedNodes) { +            $element.after(']]').after(transcludedNodes).after('[['); +          }); +        } +      })); + +      inject(function($compile, $rootScope) { +        element = $compile('<div><div ng-repeat="i in [1,2]" elm-trans>{{i}}</div></div>')($rootScope); +        $rootScope.$digest(); +        expect(element.text()).toBe('[[1]][[2]]') +      }); +    }); + + +    it('should allow mixing ngRepeat with ngInclude', inject(function($compile, $rootScope, $httpBackend) { +      $httpBackend.whenGET('someTemplate.html').respond('<p>some template; </p>'); +      element = $compile('<div><div ng-repeat="i in [1,2]" ng-include="\'someTemplate.html\'"></div></div>')($rootScope); +      $rootScope.$digest(); +      $httpBackend.flush(); +      expect(element.text()).toBe('some template; some template; '); +    })); + + +    it('should allow mixing ngRepeat with ngIf', inject(function($compile, $rootScope) { +      element = $compile('<div><div ng-repeat="i in [1,2,3,4]" ng-if="i % 2 == 0">{{i}};</div></div>')($rootScope); +      $rootScope.$digest(); +      expect(element.text()).toBe('2;4;'); +    })); +  }); + +    describe('ngRepeatStart', function () {      it('should grow multi-node repeater', inject(function($compile, $rootScope) {        $rootScope.show = false; | 
