|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | describe('ngRepeat', function() {
|
4 |
| - var element, $compile, scope, $exceptionHandler; |
| 4 | + var element, $compile, scope, $exceptionHandler, $compileProvider; |
| 5 | + |
| 6 | + beforeEach(module(function(_$compileProvider_) { |
| 7 | + $compileProvider = _$compileProvider_; |
| 8 | + })); |
5 | 9 |
|
6 | 10 |
|
7 | 11 | beforeEach(module(function($exceptionHandlerProvider) {
|
@@ -448,6 +452,95 @@ describe('ngRepeat', function() {
|
448 | 452 | });
|
449 | 453 |
|
450 | 454 |
|
| 455 | + describe('nesting in replaced directive templates', function() { |
| 456 | + |
| 457 | + it('should work when placed on a root element of attr directive with SYNC replaced template', |
| 458 | + inject(function($templateCache, $compile, $rootScope) { |
| 459 | + $compileProvider.directive('replaceMeWithRepeater', function() { |
| 460 | + return { |
| 461 | + replace: true, |
| 462 | + template: '<span ng-repeat="i in items">{{log(i)}}</span>' |
| 463 | + } |
| 464 | + }); |
| 465 | + element = jqLite('<span replace-me-with-repeater></span>'); |
| 466 | + $compile(element)($rootScope); |
| 467 | + expect(element.text()).toBe(''); |
| 468 | + var logs = []; |
| 469 | + $rootScope.log = function(t) { logs.push(t); }; |
| 470 | + |
| 471 | + // This creates one item, but it has no parent so we can't get to it |
| 472 | + $rootScope.items = [1, 2]; |
| 473 | + $rootScope.$apply(); |
| 474 | + |
| 475 | + // This cleans up to prevent memory leak |
| 476 | + $rootScope.items = []; |
| 477 | + $rootScope.$apply(); |
| 478 | + expect(angular.mock.dump(element)).toBe('<!-- ngRepeat: i in items -->'); |
| 479 | + expect(logs).toEqual([1, 2, 1, 2]); |
| 480 | + })); |
| 481 | + |
| 482 | + |
| 483 | + iit('should work when placed on a root element of attr directive with ASYNC replaced template', |
| 484 | + inject(function($templateCache, $compile, $rootScope) { |
| 485 | + $compileProvider.directive('replaceMeWithRepeater', function() { |
| 486 | + return { |
| 487 | + replace: true, |
| 488 | + templateUrl: 'replace-me-with-repeater.html' |
| 489 | + } |
| 490 | + }); |
| 491 | + $templateCache.put('replace-me-with-repeater.html', '<div ng-repeat="i in items">{{log(i)}}</div>'); |
| 492 | + element = jqLite('<span>-</span><span replace-me-with-repeater></span><span>-</span>'); |
| 493 | + $compile(element)($rootScope); |
| 494 | + expect(element.text()).toBe('--'); |
| 495 | + var logs = []; |
| 496 | + $rootScope.log = function(t) { logs.push(t); }; |
| 497 | + |
| 498 | + // This creates one item, but it has no parent so we can't get to it |
| 499 | + $rootScope.items = [1, 2]; |
| 500 | + $rootScope.$apply(); |
| 501 | + |
| 502 | + // This cleans up to prevent memory leak |
| 503 | + $rootScope.items = []; |
| 504 | + $rootScope.$apply(); |
| 505 | + expect(sortedHtml(element)).toBe('<span>-</span><!-- ngRepeat: i in items --><span>-</span>'); |
| 506 | + expect(logs).toEqual([1, 2, 1, 2]); |
| 507 | + })); |
| 508 | + |
| 509 | + |
| 510 | + it('should work when placed on a root element of element directive with SYNC replaced template', |
| 511 | + inject(function($templateCache, $compile, $rootScope) { |
| 512 | + $compileProvider.directive('replaceMeWithRepeater', function() { |
| 513 | + return { |
| 514 | + restrict: 'E', |
| 515 | + replace: true, |
| 516 | + template: '<div ng-repeat="i in [1,2,3]">{{i}}</div>' |
| 517 | + } |
| 518 | + }); |
| 519 | + element = $compile('<div><replace-me-with-repeater></replace-me-with-repeater></div>')($rootScope); |
| 520 | + expect(element.text()).toBe(''); |
| 521 | + $rootScope.$apply(); |
| 522 | + expect(element.text()).toBe('123'); |
| 523 | + })); |
| 524 | + |
| 525 | + |
| 526 | + it('should work when placed on a root element of element directive with ASYNC replaced template', |
| 527 | + inject(function($templateCache, $compile, $rootScope) { |
| 528 | + $compileProvider.directive('replaceMeWithRepeater', function() { |
| 529 | + return { |
| 530 | + restrict: 'E', |
| 531 | + replace: true, |
| 532 | + templateUrl: 'replace-me-with-repeater.html' |
| 533 | + } |
| 534 | + }); |
| 535 | + $templateCache.put('replace-me-with-repeater.html', '<div ng-repeat="i in [1,2,3]">{{i}}</div>'); |
| 536 | + element = $compile('<div><replace-me-with-repeater></replace-me-with-repeater></div>')($rootScope); |
| 537 | + expect(element.text()).toBe(''); |
| 538 | + $rootScope.$apply(); |
| 539 | + expect(element.text()).toBe('123'); |
| 540 | + })); |
| 541 | + }); |
| 542 | + |
| 543 | + |
451 | 544 | describe('stability', function() {
|
452 | 545 | var a, b, c, d, lis;
|
453 | 546 |
|
|
0 commit comments