|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -describe('ngMessages', function() { |
| 3 | +fdescribe('ngMessages', function() { |
4 | 4 | beforeEach(inject.strictDi());
|
5 | 5 | beforeEach(module('ngMessages'));
|
6 | 6 |
|
@@ -605,6 +605,51 @@ describe('ngMessages', function() {
|
605 | 605 | });
|
606 | 606 | });
|
607 | 607 |
|
| 608 | + |
| 609 | + it('should clean-up the ngMessage scope when a message is removed', |
| 610 | + inject(function($compile, $rootScope) { |
| 611 | + function countWatchers() { |
| 612 | + var scope = $rootScope; |
| 613 | + var watchers = 0; |
| 614 | + |
| 615 | + while (scope) { |
| 616 | + watchers += scope.$$watchers.length; |
| 617 | + if (scope.$$childHead) { |
| 618 | + scope = scope.$$childHead; |
| 619 | + } else if (scope.$$nextSibling) { |
| 620 | + scope = scope.$$nextSibling; |
| 621 | + } else { |
| 622 | + scope = null; |
| 623 | + } |
| 624 | + } |
| 625 | + |
| 626 | + return watchers; |
| 627 | + } |
| 628 | + |
| 629 | + var html = |
| 630 | + '<div ng-messages="items">' + |
| 631 | + '<div ng-message="a">{{forA}}</div>' + |
| 632 | + '</div>'; |
| 633 | + |
| 634 | + element = $compile(html)($rootScope); |
| 635 | + $rootScope.$apply(function() { |
| 636 | + $rootScope.forA = 'A'; |
| 637 | + $rootScope.items = {a: true}; |
| 638 | + }); |
| 639 | + |
| 640 | + expect(element.text()).toBe('A'); |
| 641 | + var watchers = countWatchers(); |
| 642 | + |
| 643 | + $rootScope.$apply('items.a = false'); |
| 644 | + |
| 645 | + expect(element.text()).toBe(''); |
| 646 | + // We don't know exactly how many watchers are on the scope, only that there should be |
| 647 | + // one less now |
| 648 | + expect(countWatchers()).toBe(watchers-1); |
| 649 | + }) |
| 650 | + ); |
| 651 | + |
| 652 | + |
608 | 653 | describe('when including templates', function() {
|
609 | 654 | they('should work with a dynamic collection model which is managed by ngRepeat',
|
610 | 655 | {'<div ng-messages-include="...">': '<div ng-messages="item">' +
|
|
0 commit comments