【发布时间】:2015-07-09 16:36:01
【问题描述】:
指令的单元测试,其中escope是隔离的范围
我也尝试使用 $rootScope.$apply() 和 $rootScope.$digest() init_data() 虽然没有从单元测试中调用:(((。模态是 angularStrap 模态。
it('should open the dialog', function(){
spyOn(escope.mainModal.$promise, "then").and.callFake(function() {
var deferred = $q.defer();
deferred.resolve(true);
return deferred.promise;
});
spyOn(escope, 'init_data');
escope.openDialog();
escope.$apply();
expect(escope.mainModal.$promise.then).toHaveBeenCalled();
expect(escope.init_data).toHaveBeenCalled();
});
在指令中..
$scope.openDialog = function() {
$scope.mainModal.$promise.then(function(f) {
debugger
$scope.init_data();
});
}
第一个间谍通过,但 init_data 间谍失败。对于我的生活,我无法弄清楚这一点。
【问题讨论】:
-
如果您从代码中取出
debugger调用会发生什么? -
仍然失败。我把调试器放进去看看promise是否正在解决。不是:(
标签: javascript angularjs unit-testing jasmine angular-strap