blob: 85d07c6cf349a429fc70edaef813cad83409372c [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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});