• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {TimeUtils} from './time_utils';
18
19describe('TimeUtils', () => {
20  it('waits for condition', async () => {
21    let success = false;
22    setTimeout(() => {
23      success = true;
24    }, 200);
25    await expectAsync(TimeUtils.wait(() => success, 1000)).toBeResolved();
26  });
27
28  it('times out waiting for condition', async () => {
29    let success = false;
30    const promise = TimeUtils.sleepMs(200).then(() => {
31      success = true;
32    });
33    await expectAsync(TimeUtils.wait(() => success, 100, 50)).toBeRejected();
34    await promise;
35  });
36
37  it('checks condition based on interval', async () => {
38    let success = false;
39    const promise = TimeUtils.sleepMs(250).then(() => {
40      success = true;
41    });
42    await expectAsync(TimeUtils.wait(() => success, 500, 500)).toBeRejected();
43    await promise;
44  });
45});
46