本文整理汇总了TypeScript中Sinon.SinonStub.callsFake方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SinonStub.callsFake方法的具体用法?TypeScript SinonStub.callsFake怎么用?TypeScript SinonStub.callsFake使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sinon.SinonStub
的用法示例。
在下文中一共展示了SinonStub.callsFake方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
appStateStub.enqueueResponse('get', false); // loader.isSyncing
appStateStub.enqueueResponse('get', true); // rounds.isLoaded
appStateStub.enqueueResponse('get', false); // rounds.isTicking
appStateStub.enqueueResponse('get', 10); // node.consensus
appStateStub.enqueueResponse('getComputed', false); // node.poorConsensus
loadKeypairs();
// currentSlot must not be the same slot of lastBlock => This will pass
slotsStub.enqueueResponse('getSlotNumber', 97);
slotsStub.enqueueResponse('getSlotNumber', 98);
// currentSlot must have the same slotNumber of blockData => This will get catched
slotsStub.enqueueResponse('getSlotNumber', 100);
slotsStub.enqueueResponse('getSlotNumber', 100);
getBlockSlotDataStub = sandbox.stub(instance, 'getBlockSlotData').resolves({ time: 11111, keypair: {} });
broadcasterLogicStub.enqueueResponse('getPeers', Promise.resolve());
blocksProcessModuleStub.enqueueResponse('generateBlock', Promise.resolve());
catcherStub = sandbox.stub(helpers, 'catchToLoggerAndRemapError');
catcherStub.callsFake((rejectString) => {
return (err: Error) => {
catcherLastErr = err;
return Promise.reject(rejectString);
};
});
catcherLastErr = null;
});
示例2: it
it('should set the block to null if findOne returns null', async () => {
findOneStub.returns(null);
genBBStub.callsFake((a) => a);
await instance.getBlocksCommon('1,2,3', req);
expect(genBBStub.notCalled).to.be.true;
expect(getResStub.calledOnce).to.be.true;
expect(getResStub.firstCall.args).to.be.deep.equal([{common: null}, 'transportBlocks', 'commonBlock']);
});
示例3: it
it('should set .isProcessing to true to prevent shutdowns', async () => {
txStub.callsFake((t) => {
expect(inst['isProcessing']).to.be.true;
return t('tx');
});
await inst.applyBlock(block, false, false, accountsMap);
// tslint:disable-next-line: no-string-literal
expect(inst['isProcessing']).to.be.false;
});
示例4: beforeEach
beforeEach(() => {
roundLogicStubConstructor = () => {
return roundLogicStub;
};
sandbox = sinon.createSandbox();
container = createContainer();
container.bind(roundLogicSymbol).to(RoundLogicStub).inSingletonScope();
container.bind(Symbols.logic.round).to(RoundLogicStub).inSingletonScope();
container.rebind(Symbols.helpers.constants).toConstantValue(constants);
container.rebind(Symbols.modules.rounds).to(RoundsModule).inSingletonScope();
block = BlocksModel.classFromPOJO(createFakeBlock());
previousBlock = BlocksModel.classFromPOJO(createFakeBlock());
instance = container.get(Symbols.modules.rounds);
delegatesModuleStub = container.get(Symbols.modules.delegates);
accountsModuleStub = container.get(Symbols.modules.accounts);
loggerStub = container.get(Symbols.helpers.logger);
slotsStub = container.get(Symbols.helpers.slots);
busStub = container.get(Symbols.helpers.bus);
socketIOStub = container.get(Symbols.generic.socketIO);
appStateStub = container.get(Symbols.logic.appState);
roundsLogicStub = container.get(Symbols.logic.rounds);
roundLogicStub = container.get(roundLogicSymbol);
roundLogicStubConstructorSpy = sandbox.spy(roundLogicStubConstructor);
// TODO check if there is a way to achieve this with inversify...
(instance as any).RoundLogic = roundLogicStubConstructorSpy;
roundLogicScope = {
backwards : false,
dposV2: false,
block : {
generatorPublicKey: block.generatorPublicKey,
height : block.height,
id : block.id,
} as any,
finishRound : false,
library : {
logger: {} as any,
},
modules : {
accounts: {} as any,
},
models : {
AccountsModel: container.get(Symbols.models.accounts),
BlocksModel : container.get(Symbols.models.blocks),
RoundsModel : container.get(Symbols.models.rounds),
},
round : 12,
roundDelegates: [],
roundFees : 10.1,
roundOutsiders: [],
roundRewards : [100],
};
innerTickStub = sandbox.stub(instance as any, 'innerTick');
// Expose the passed txGenerator so we can test it
innerTickStub.callsFake((blk, transaction, backwards, txGen, afterTx = () => Promise.resolve(null)) => {
txGenerator = txGen;
afterTxPromise = afterTx;
return Promise.resolve('innerTick DONE');
});
roundLogicStub.stubs.mergeBlockGenerator.resolves();
roundLogicStub.stubs.undo.resolves();
roundLogicStub.stubs.markBlockId.resolves();
roundLogicStub.stubs.truncateBlocks.resolves();
roundLogicStub.stubs.apply.resolves();
busStub.stubs.message.returns(void 0);
});