當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。