diff options
| author | Igor Minar | 2013-11-04 10:28:30 -0800 | 
|---|---|---|
| committer | Igor Minar | 2013-11-04 10:35:51 -0800 | 
| commit | 9483373c331343648e079420b3eb1f564d410ff2 (patch) | |
| tree | 7a55acfaa790da3dce21cfc786d9f239ee1bbc4a /test | |
| parent | c6923d2df466c80ef3b6a4699da53ff0dcf8fd7a (diff) | |
| download | angular.js-9483373c331343648e079420b3eb1f564d410ff2.tar.bz2 | |
fix(ngIf): destroy child scope when destroying DOM
Diffstat (limited to 'test')
| -rwxr-xr-x | test/ng/directive/ngIfSpec.js | 22 | 
1 files changed, 21 insertions, 1 deletions
| diff --git a/test/ng/directive/ngIfSpec.js b/test/ng/directive/ngIfSpec.js index 509cf26d..ce4de98c 100755 --- a/test/ng/directive/ngIfSpec.js +++ b/test/ng/directive/ngIfSpec.js @@ -36,7 +36,7 @@ describe('ngIf', function () {      expect(element.children().length).toBe(0);    }); -  it('should create a new scope', function () { +  it('should create a new scope every time the expression evaluates to true', function () {      $scope.$apply('value = true');      element.append($compile(        '<div ng-if="value"><span ng-init="value=false"></span></div>' @@ -45,6 +45,26 @@ describe('ngIf', function () {      expect(element.children('div').length).toBe(1);    }); +  it('should destroy the child scope every time the expression evaluates to false', function() { +    $scope.value = true; +    element.append($compile( +        '<div ng-if="value"></div>' +    )($scope)); +    $scope.$apply(); + +    var childScope = element.children().scope(); +    var destroyed = false; + +    childScope.$on('$destroy', function() { +      destroyed = true; +    }); + +    $scope.value = false; +    $scope.$apply(); + +    expect(destroyed).toBe(true); +  }); +    it('should play nice with other elements beside it', function () {      $scope.values = [1, 2, 3, 4];      element.append($compile( | 
