当我的函数返回一个链式承诺时,我遇到了sinon的问题。 最后一次通话是外部http呼叫。
A.ts:
export function someFunctionInClassB(x,y){
return some requestPromise.then( // this is the external http
(resC) =>
// some code processing resC
// return resB
);
}
B.ts:
const stubbed = sinon.stub(someBinstance, "someFunctionInClassB");
stubbed.withArgs(x,y).resolves(fakeResB);
someAinstance.init(someBinstance);
stubbed.withArgs(x,y).resolves(fakeResB);
someAinstance.init(someBinstance);
const myWantedRes = someAinstance.someFunctionInClassA(x,y);
我想要someFunctionInClassA获取一个假的resB(所以我不需要进行外部调用),并为这个假的resB获取someResult。我做了:
@Configuration
class SeviceConfig {
@Bean
@ConditionalOnMissingClass(name = "your.app.ServiceImpl")
ServiceInterface service() {
return new ServiceStubImpl(...);
}
}
我试着使用ant而没有用假包装我的fakeResB。 我试着在myWantedRes中调用.then。 求救!