blob: e2f9a8e8e4113c3c60e2b6df3187c3f5659ee914 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import sinon from 'sinon';
6import {assert} from 'chai';
7import {CronTask} from './cron.js';
8
9let clock;
10
11describe('cron', () => {
12 beforeEach(() => {
13 clock = sinon.useFakeTimers();
14 });
15
16 afterEach(() => {
17 clock.restore();
18 });
19
20 it('calls task periodically', () => {
21 const task = sinon.spy();
22 const cronTask = new CronTask(task, 1000);
23
24 // Make sure task is not called until the cron task has been started.
25 assert.isFalse(task.called);
26
27 cronTask.start();
28 assert.isTrue(task.calledOnce);
29
30 clock.tick(1000);
31 assert.isTrue(task.calledTwice);
32
33 clock.tick(1000);
34 assert.isTrue(task.calledThrice);
35 });
36});