From 2315d9b3610994b36c44e4a97fb1427d59471ce8 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 14 Mar 2012 13:03:53 -0700 Subject: fix(ng-switch): properly destroy child scopes --- test/directive/ngSwitchSpec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/directive/ngSwitchSpec.js b/test/directive/ngSwitchSpec.js index c61dd60d..b0dd7493 100644 --- a/test/directive/ngSwitchSpec.js +++ b/test/directive/ngSwitchSpec.js @@ -60,4 +60,34 @@ describe('ng-switch', function() { expect($rootScope.name).toEqual('works'); expect(element.text()).toEqual('works'); })); + + + it('should properly create and destory child scopes', inject(function($rootScope, $compile) { + element = $compile( + '' + + '
{{name}}
' + + '
')($rootScope); + $rootScope.$apply(); + + var getChildScope = function() { return element.find('div').scope(); }; + + expect(getChildScope()).toBeUndefined(); + + $rootScope.url = 'a'; + $rootScope.$apply(); + var child1 = getChildScope(); + expect(child1).toBeDefined(); + spyOn(child1, '$destroy'); + + $rootScope.url = 'x'; + $rootScope.$apply(); + expect(getChildScope()).toBeUndefined(); + expect(child1.$destroy).toHaveBeenCalledOnce(); + + $rootScope.url = 'a'; + $rootScope.$apply(); + var child2 = getChildScope(); + expect(child2).toBeDefined(); + expect(child2).not.toBe(child1); + })); }); -- cgit v1.2.3