[英]Jasmine - How to chain a `.then` and a `.finally` in a callFake spy?
I have the following function, that does a service call with a promise and a .finally
: 我有以下函数,该函数使用promise和
.finally
进行服务调用:
myService.getStuff().then(function() {
this.doStuffWhenServiceOK();
}, function () {
this.doStuffWhenServiceFails();
}).finally(function() {
this.doFinally();
});
I am spying on this service with the following spy: 我通过以下间谍监视这项服务:
spyOn(myService, 'getStuff').and.callFake(function() {
return {
then: function (succesFn, errorFn) {
return succesFn();
}
};
});
The problem is that the test complains that the .finally
is not known. 问题在于测试抱怨
.finally
未知。 Just adding it after .then
does not seem to be a solution... 仅在
.then
之后添加它似乎不是解决方案...
return {
then: function(successFn) {
return successFn();
},
finally: function(successFn) {
return successFn();
}
}
Who knows how to chain .then
and .finally
in the callFake
spy? 谁知道链如何
.then
和.finally
在callFake
间谍吗?
I work with Angular 1. 我使用Angular 1。
Return a finally function. 返回一个finally函数。
function then(succesFn, errorFn) {
succesFn();
return {finally:function() {}};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.