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


TypeScript SinonStub.onCall方法代码示例

本文整理汇总了TypeScript中Sinon.SinonStub.onCall方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SinonStub.onCall方法的具体用法?TypeScript SinonStub.onCall怎么用?TypeScript SinonStub.onCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sinon.SinonStub的用法示例。


在下文中一共展示了SinonStub.onCall方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: beforeEach

    beforeEach(() => {
      destroyStub            = sandbox.stub();
      blocksModule.lastBlock = {
        height       : 10,
        previousBlock: 'previousBlock',
        transactions : [
          { senderPublicKey: 'first' },
          { senderPublicKey: 'second' },
          { senderPublicKey: 'third' },
        ],
        destroy      : destroyStub,
      } as any;
      roundsModule.enqueueResponse('backwardTick', Promise.resolve());
      txLogic.stubs.undoUnconfirmed.resolves([]);
      txLogic.stubs.undo.resolves([]);
      dbStub.stubs.performOps.resolves();
      // accountsModule.stubs.getAccount.callsFake((a) => a);
      accountsModule.stubs.resolveAccountsForTransactions.callsFake((txs)=> {
        const toRet = {};
        txs.forEach((tx) => toRet[tx.senderId] = tx.senderId);
        return toRet;
      });
      sandbox.stub(blocksModel.sequelize, 'transaction').callsFake((cb) => {
        return cb('tx');
      });
      findStub = sandbox.stub(blocksModel, 'findById');
      findStub.onCall(0).resolves(blocksModule.lastBlock);
      findStub.onCall(1).resolves({toJSON() { return { id: 'previousBlock' }}});

      const accountsModel = container.get<any>(Symbols.models.accounts);
      accountsFindStub    = sandbox.stub().returns('senderAccount');
      accountsScopeStub   = sandbox.stub(accountsModel, 'scope').returns({
        find: accountsFindStub
      });
    });
开发者ID:RiseVision,项目名称:rise-node,代码行数:35,代码来源:chain.spec.ts

示例2: it

      it('should not throw error if only address === query.address and check of setting address in query.address if query.publicKey is empty', async () => {
        isEmptyStub.onCall(1).returns(true);
        isEmptyStub.onCall(2).returns(false);
        isEmptyStub.onCall(3).returns(false);

        await expect(instance.getAccount(query)).to.be.not.rejectedWith('Account publicKey does not match address');
      });
开发者ID:RiseVision,项目名称:rise-node,代码行数:7,代码来源:accountsAPI.spec.ts

示例3: it

    it('is set to false after a series of retry that fail that succeed', function(done) {
      const firstResponse = new Response(null, { status: 500 });
      const secondResponse = new Response(null, { status: 200 });

      fetch.onCall(0).returns(Promise.resolve(firstResponse));
      fetch.onCall(1).returns(Promise.resolve(secondResponse));

      client.configure(config => config.rejectErrorResponses().withRetry({
        maxRetries: 3,
        interval: 1,
        strategy: retryStrategy.fixed
      }));

      expect(client.isRequesting, 'Before start').to.equal(false);
      const request = client.fetch('path');
      expect(client.isRequesting, 'When started').to.equal(true);
      request.then(() => {
        // 1 original call plus 1 retry
        expect(fetch).to.have.callCount(2);
        expect(client.isRequesting, 'When finished').to.equal(false);
        done();
      }).catch((result) => {
        done('fetch did error');
      });
    });
开发者ID:aurelia,项目名称:aurelia,代码行数:25,代码来源:http-client.spec.ts

示例4: beforeEach

 beforeEach(() => {
   updateMissedBlocks = sandbox.stub(instance, 'updateMissedBlocks').returns({updateMissed: true});
   applyRound         = sandbox.stub(instance, 'applyRound').returns([{apply: 1}, {apply: 2}]);
   restoreVotesSnapshot = sandbox.stub(instance, 'restoreVotesSnapshot').returns({restorevotes: true});
   reCalcVotes        = sandbox.stub(instance, 'reCalcVotes');
   reCalcVotes.onCall(0).returns({reCalcVotes: 1});
   reCalcVotes.onCall(1).returns({reCalcVotes: 2});
 })
开发者ID:RiseVision,项目名称:rise-node,代码行数:8,代码来源:round.spec.ts

示例5: beforeEach

    beforeEach(() => {
      generatedAddress = 'generatedAddress';
      query            = {
        address  : 'address',
        publicKey: 'publicKey',
      };
      accData          = {
        _timestampAttributes: {},
        address             : 'address',
        balance             : 'balance',
        multisignatures     : [],
        publicKey           : Buffer.from('0011aabbccddeeff0011aabbccddeeff0011aabbccddeeff0011aabbccddeeff', 'hex'),
        secondPublicKey     : Buffer.from('1111aabbccddeeff0011aabbccddeeff0011aabbccddeeff0011aabbccddeeff', 'hex'),
        secondSignature     : 1,
        u_balance           : '10000',
        u_multisignatures   : [],
        u_secondSignature   : 1,
      };

      accountsModule.enqueueResponse('generateAddressByPublicKey', generatedAddress);
      accountsModule.enqueueResponse('getAccount', Promise.resolve(new AccountsModel(accData)));

      isEmptyStub = sandbox.stub();
      isEmptyStub.onCall(0).returns(false)
        .onCall(1).returns(false)
        .onCall(2).returns(true)
        .onCall(3).returns(true);
    });
开发者ID:RiseVision,项目名称:rise-node,代码行数:28,代码来源:accountsAPI.spec.ts

示例6: it

 it('should throw error if previousblock is null', async () => {
   blocksUtils.reset();
   findStub.onCall(0).resolves(null);
   await expect(inst.deleteLastBlock()).to.be.rejectedWith('previousBlock is null');
   expect(findStub.called).is.true;
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:6,代码来源:chain.spec.ts


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