测试完成后,我应该在范围上调用$ destroy吗?
问题描述:
在我的测试中,我创建了手角控制器制造$scope
:
beforeEach(function() {
inject(function($controller, $rootScope) {
$scope = $rootScope.$new();
controller = $controller('ContentController', {$scope: $scope});
});
});
是否有必要每次打电话试运行后$scope.$destroy()
?
afterEach(function() {
$scope.$destroy();
});
答
这不是必要的,只有语义。
https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope#$ destroy
+0
我用它作为控制器,它没有提到测试。 – Blacksonic 2015-04-06 07:37:31
我从来没有做过,测试是短暂反正。除非您想要检查$ destroy事件的某些事件处理程序。 – Chandermani 2015-04-04 13:42:31