UNPKG

1.49 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC. All Rights Reserved.
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 * as tf from './index';
18import { ALL_ENVS, describeWithFlags } from './jasmine_util';
19describeWithFlags('nextFrame', ALL_ENVS, () => {
20 it('basic usage', async () => {
21 const t0 = tf.util.now();
22 await tf.nextFrame();
23 const t1 = tf.util.now();
24 // tf.util.now should give sufficient accuracy on all supported envs.
25 expect(t1 > t0);
26 });
27 it('does not block timers', async () => {
28 let flag = false;
29 setTimeout(() => {
30 flag = true;
31 }, 50);
32 const t0 = tf.util.now();
33 expect(flag).toBe(false);
34 while (tf.util.now() - t0 < 1000 && !flag) {
35 await tf.nextFrame();
36 }
37 expect(flag).toBe(true);
38 });
39});
40//# sourceMappingURL=browser_util_test.js.map
\No newline at end of file