当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript SinonStub.callsFake方法代码示例

本文整理汇总了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;
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:25,代码来源:forge.spec.ts

示例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']);
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:8,代码来源:transportV2API.spec.ts

示例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;
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:9,代码来源:chain.spec.ts

示例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);
  });
开发者ID:RiseVision,项目名称:rise-node,代码行数:67,代码来源:rounds.spec.ts


注:本文中的Sinon.SinonStub.callsFake方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。