本文整理匯總了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();
});
示例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();
});
示例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();
});
示例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();
});
});
示例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()
})
})
})
示例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;
});
示例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();
});
示例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();
});
});