本文整理汇总了TypeScript中lolex.install函数的典型用法代码示例。如果您正苦于以下问题:TypeScript install函数的具体用法?TypeScript install怎么用?TypeScript install使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了install函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should ignore bank holiday to compute the next date', () => {
const clock = lolex.install({ now: new Date('2017-08-14T16:00') });
const nextRunAt = Routine.computeNextRunAt('0 12 * * *', true);
clock.uninstall();
expect(nextRunAt).toEqual(new Date('2017-08-15T12:00'));
});
示例2: it
it('should load and start every routine', async () => {
const clock = lolex.install();
await routineService.load();
clock.uninstall();
expect(clock.countTimers()).toBe(2);
});
示例3: it
it('should resolve with the cached token if there is a valid one', () => {
// given
const clock = lolex.install();
const initialLifetime = 3600;
const timeBeforeExpiry = initialLifetime * (1 - defaultCacheConfig.percentageLeft) * 1000 - 1;
nock(oauthHost)
.post('/access_token')
.reply(HttpStatus.OK, {
access_token: defaultAccessTokenValue,
expires_in: initialLifetime
})
.get('/tokeninfo')
.query({ access_token: defaultAccessTokenValue })
.reply(HttpStatus.OK, defaultTokenInfoResponse);
// when
const tokenService = new TokenCache({
'nucleus': ['nucleus.write', 'nucleus.read'],
'halo': ['all']
}, oauthConfig);
const promise = tokenService.get('nucleus')
.then(() => clock.tick(timeBeforeExpiry))
.then(() => tokenService.get('nucleus'))
.then((token) => {
clock.uninstall();
return token.access_token;
});
// then
return expect(promise).to.become(defaultAccessTokenValue);
});
示例4: it
it('should enable routine and compute nextRunAt', async () => {
const clock = lolex.install({ now: new Date('2017-08-12T16:00:00') });
const response = await request(app)
.patch(`/api/routines/${initRoutines[2].routineId}`)
.set('Accept', 'application/json')
.set('x-access-token', user.token)
.send({
sceneId: 'faaed78e-fd1c-4717-b610-65d2fa3d01b2',
name: 'routine_updated',
interval: '0 12 * * *',
enabled: true,
});
expect(response.status).toHaveStatusOk();
expect(clock.countTimers()).toBe(1);
const routine = await knex(Routine.TABLE)
.first()
.where('routineId', initRoutines[2].routineId);
expect(routine.nextRunAt).toEqual(
new Date('2017-08-13T12:00:00').getTime(),
);
expect(routine).toMatchSnapshot({
createdAt: expect.any(Number),
updatedAt: expect.any(Number),
nextRunAt: expect.any(Number),
});
clock.uninstall();
});
示例5: TestMongo
test.beforeEach(async t => {
const testmongo = new TestMongo()
const db = await testmongo.getDb()
t.log(`Database ${testmongo.getUrl()} created`)
t.context = {
ms: new DBMediaService(LoggerMock('test'), {
dbUrl: testmongo.getUrl(),
}),
mongo: testmongo,
clock: lolex.install(),
}
await t.context.ms.connect()
})