TypeScript Sinon调用假返回类型不匹配

时间:2018-11-20 18:56:56

标签: typescript sinon

当我尝试使用sinon存根调用伪造函数时,总是出现此错误。 [ts] Argument of type '(contactStructure: ContactStructure, sourceValue: any) => Promise<{ value: undefined; failure: { contactStructure: ContactStructure; sourceValue: any; }; }>' is not assignable to parameter of type '() => any'. [2345] 我正在使用sinon的7.1.1版本和@ types / sinon的5.0.6版本

这是我的存根:

private cnctMappingMngrStub:SinonStubbedInstance<ContactMappingManager>;
before(): void {
  this.cnctMappingMngrStub = createStubInstance(ContactMappingManager);
}

这是我要叫假货的地方。

  this.cnctMappingMngrStub.getMappedValue
  .onCall(1).callsFake(async (contactStructure: ContactStructure, sourceValue: any) => {
    return Promise.resolve({
      value: undefined,
      failure: {
        contactStructure,
        sourceValue
      }
    });
  });

我想我明白问题出在哪里...我想。给出此错误的原因是,当函数希望返回的类型为() => any时,其返回类型为Promise<{ value: undefined; failure: { contactStructure: ContactStructure; sourceValue: any; }; }>。我只是不知道如何解决。任何帮助都将不胜感激。

谢谢

〜伊桑

0 个答案:

没有答案