gpt4 book ai didi

javascript - 类型错误 : Attempted to wrap getRepository which is already wrapped

转载 作者:行者123 更新时间:2023-11-30 20:29:36 32 4
gpt4 key购买 nike

我需要用 sinon 多次包装一个方法,以便能够根据参数返回不同的对象。我该怎么做?

我要测试的 Controller 看起来像这样:

const servicePackagesOfferingRepository = Salesforce.getRepository(ServicePackageOffering);
const servicePackageOffering = await servicePackagesOfferingRepository.findOneById(model.servicePackageOfferingId);

const serviceCallRepository = Salesforce.getRepository(ServiceCall);
serviceCall = await serviceCallRepository.save(serviceCall);

单元测试是这样的:

const servicePackagesOfferingRepository = new Repository(ServicePackageOffering);
const servicePackagesOfferingRepositoryMock = sandbox.mock(servicePackagesOfferingRepository);

servicePackagesOfferingRepositoryMock
.expects('findOneById')
.withArgs(inputModel.servicePackageOfferingId)
.resolves({});

sandbox
.mock(Salesforce)
.expects('getRepository')
.withArgs(ServicePackageOffering)
.returns(servicePackagesOfferingRepository);

const serviceCallRepository = new Repository(ServiceCall);
const serviceCallRepositoryMock = sandbox.mock(serviceCallRepository);

serviceCallRepositoryMock
.expects('save')
.once();

sandbox
.mock(Salesforce)
.expects('getRepository')
.withExactArgs(ServiceCall)
.returns(serviceCallRepository);

但是我得到这个错误:

TypeError: Attempted to wrap getRepository which is already wrapped

最佳答案

找到了一种方法:

const SalesforceMock = sandbox.mock(Salesforce);
SalesforceMock.expects('getRepository')
.twice()
.onFirstCall()
.returns(serviceCallRepository)
.onSecondCall()
.returns(clientRepository);

关于javascript - 类型错误 : Attempted to wrap getRepository which is already wrapped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50502307/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com