我正在尝试关注代码段,为了简化它,我删除了大部分不需要的代码。
function functionToTest() {
if(hasUnsavedChanges()){
return customService.confirm().then(function(confirmed) {
console.log(confirmed);
if(confirmed) {
return customService.openSomething().then(function (data){
console.log(data);
return customService.doneSomething();
});
} else {
return customService.doSomething().then(function (){
return customService.doSomethingBeforeDone().then(function (){
return customService.doneSomething();
});
});
}
}, function() {
return customService.doneSomething();
});
} else {
return customService.doneSomething();
}
}
当hasUnsavedChanges()返回true时,这是我的单元测试
it('should doSomething', function() {
spyOn(customService, 'confirm').and.returnValue(Promise.resolve(true));
spyOn(customService, 'openSomething').and.returnValue(Promise.resolve({data: 'something'}));
spyOn(customService, 'doneSomething').and.returnValue(Promise.resolve());
functionToTest();
$scope.$apply();
expect(customService.confirm).toHaveBeenCalled();
expect(customService.openSomething).toHaveBeenCalled();
expect(customService.doneSomething).toHaveBeenCalled();
});
正在调用customService.confirm,但未调用其他2个断言。
虽然我可以看到console.log(已确认)和console.log(数据)显示通过间谍返回的正确值
答案 0 :(得分:0)
在我的函数调用块中断言修复了它
ORA-04091: table ESPUMA.ORDER_DETAILS is mutating, trigger/function may not see it