如果 watcher 监视 $parent 范围变量,如何测试它?例如,我进入了儿童范围:
$scope.$parent.$watch('activeId', function (hotelId) {
    $scope.select(activeId);
});
目前测试的样子:
...
    beforeEach(inject(function (_$controller_, _$rootScope_) {
       $scope = _$rootScope_.$new();
       $parentScope = _$rootScope_.$new();
       $controller = _$controller_('ChildCtrl', {'$scope': $scope});
       $parentController = _$controller_('ParentCtrl', {'$scope': $parentScope});
    }));
    describe('select', function () {
        beforeEach(function () {
           spyOn($scope, 'select');
        });
        it('should call select', function () {
           $parentScope.setActiveId(1);
           $parentScope.$digest();
           expect($scope.select).toHaveBeenCalled();
        });
    });
});
但不幸的是,这个测试失败了。