當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Sinon.useFakeTimers函數代碼示例

本文整理匯總了TypeScript中Sinon.useFakeTimers函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript useFakeTimers函數的具體用法?TypeScript useFakeTimers怎麽用?TypeScript useFakeTimers使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了useFakeTimers函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

    beforeEach(() => {
        clock = sinon.useFakeTimers();
        // Pretend we are a browser
        global['navigator'] = {
            hardwareConcurrency: 8,
            oscpu: 'Win32',
            language: 'en-GB',
            userAgent: 'foo',
            platform: 'Win32'
        };

        global['screen'] = {
            width: 1024,
            height: 1024,
            colorDepth: 32,
            orientation: {
                type: 'landscape-primary'
            }
        };

        global['window'] = {
            outerWidth: 1000,
            outerHeight: 1000,
            innerWidth: 950,
            innerHeight: 950
        };
        
        subject = new UserEnvironment();

    });
開發者ID:LiberisLabs,項目名稱:raygun-angular2,代碼行數:30,代碼來源:UserEnvironment.ts

示例2: test

    test('build range filter in iso format', () => {
      const clock = sinon.useFakeTimers(moment.utc([2000, 1, 1, 0, 0, 0, 0]).valueOf());

      const filter = getTime(
        {
          id: 'test',
          title: 'test',
          timeFieldName: 'date',
          fields: [
            {
              name: 'date',
              type: 'date',
              esTypes: ['date'],
              aggregatable: true,
              searchable: true,
              filterable: true,
            },
          ],
        },
        { from: 'now-60y', to: 'now' }
      ) as Filter;
      expect(filter.range.date).to.eql({
        gte: '1940-02-01T00:00:00.000Z',
        lte: '2000-02-01T00:00:00.000Z',
        format: 'strict_date_optional_time',
      });
      clock.restore();
    });
開發者ID:elastic,項目名稱:kibana,代碼行數:28,代碼來源:get_time.test.ts

示例3: it

 it('should use current time if not passed', () => {
   const fakeTimers = sinon.useFakeTimers();
   fakeTimers.setSystemTime(112233 * 1000);
   inst.lastReceipt.update();
   expect(inst.lastReceipt.get()).to.be.eq(112233);
   fakeTimers.restore();
 });
開發者ID:RiseVision,項目名稱:rise-node,代碼行數:7,代碼來源:blocks.spec.ts

示例4: function

    function () {
      const clock = sinon.useFakeTimers();

      const autoReload = true;
      const updatePreset = sinon.stub().returns(Promise.resolve());
      const applyCustomization = sinon.spy();
      const reload = sinon.spy();
      const cancel = sinon.stub();
      const showCustomizationMessage = sinon.spy();

      return applyDetection('', '', undefined, undefined, undefined, autoReload,
        updatePreset, applyCustomization, reload, cancel, showCustomizationMessage)
        .then(() => {
          // No functions should have been called before 1s
          clock.tick(999);
          expect(applyCustomization.called).to.be.false;
          expect(reload.called).to.be.false;
          expect(showCustomizationMessage.called).to.be.false;

          // Only 'applyCustomization' and 'reload' functions should have been called on 1s
          clock.tick(1);
          expect(applyCustomization.called).to.be.true;
          expect(reload.called).to.be.true;
          expect(showCustomizationMessage.called).to.be.false;

          clock.restore();
        });
    });
開發者ID:yomed,項目名稱:vscode-icons,代碼行數:28,代碼來源:autoDetectProject.test.ts

示例5: test

    test('failed RPC call', function (done) {
      var clock = sinon.useFakeTimers()

      var daemon = new stratum.Daemon({
        path: '/doesnt/exist/%s',
        datadir: 'data/dir',
        port: 8080,
        host: 'localhost',
        user: 'user',
        password: 'pass',
        name: 'Mycoin'
      })

      sinon.stub(daemon.rpc, 'call').callsFake(function (name, params, callback) {
        if (name === 'test') {
          callback('error')
        }
      })

      daemon.call('test').catch(function (message) {
        expect(message).to.equal('error')
      }).done(function () {
        var promise = daemon.call('timeout')
        clock.tick(4000)

        promise.catch(function (message) {
          expect(message).to.be('Command timed out')
        }).done(function () {
          clock.restore()
          done()
        })
      })

    })
開發者ID:pocesar,項目名稱:node-stratum,代碼行數:34,代碼來源:tests.ts

示例6: it

    it('can temporarily be disabled with ssrForceFetchDelay', () => {
      clock = sinon.useFakeTimers();

      const client = new ApolloClient({
        networkInterface,
        ssrForceFetchDelay: 100,
        addTypename: false,
      });

      // Run a query first to initialize the store
      const outerPromise = client.query({ query })
        // then query for real
        .then(() => {
          const promise = client.query({ query, forceFetch: true });
          clock.tick(0);
          return promise;
        })
        .then((result) => {
          assert.deepEqual(result.data, { myNumber: { n: 1 } });
          clock.tick(100);
          const promise = client.query({ query, forceFetch: true });
          clock.tick(0);
          return promise;
        })
        .then((result) => {
          assert.deepEqual(result.data, { myNumber: { n: 2 } });
        });
      clock.tick(0);
      return outerPromise;
    });
開發者ID:drager,項目名稱:apollo-client,代碼行數:30,代碼來源:client.ts

示例7: beforeEach

 beforeEach(async () => {
     await blockchainLifecycle.startAsync();
     const sinonTimerConfig = { shouldAdvanceTime: true } as any;
     // This constructor has incorrect types
     timer = Sinon.useFakeTimers(sinonTimerConfig);
     currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
     expirationWatcher = new ExpirationWatcher();
 });
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:8,代碼來源:expiration_watcher_test.ts

示例8: it

    it('should calculate `nextRunAt` with `interval`', () => {
        const clock = sinon.useFakeTimers(new Date('2016-07-05 22:02:50').getTime());

        return instance.every((1000 * 60 * 5), 'task5', {qwe: 'asd'}).then((createdTask) => {
            createdTask.nextRunAt.getTime().should.be.equal(new Date('2016-07-05 22:07:50').getTime());
            clock.restore();
        });
    });
開發者ID:CodeZavod,項目名稱:scheduler,代碼行數:8,代碼來源:index.ts


注:本文中的Sinon.useFakeTimers函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。