1
1
import { describe , it , expect , vi , beforeEach } from "vitest" ;
2
2
import { bootstrap_custom_element } from "./index" ;
3
3
4
- const delay = ( ms ?: number ) =>
5
- new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
4
+ const awaitAnimationFrame = ( ) =>
5
+ new Promise ( ( resolve ) => window . requestAnimationFrame ( resolve ) ) ;
6
6
7
7
describe ( "bootstrap_custom_element" , ( ) => {
8
8
const create = vi . fn ( ) ;
@@ -20,7 +20,7 @@ describe("bootstrap_custom_element", () => {
20
20
import gradio as gr
21
21
</gradio-lite>
22
22
` ;
23
- await delay ( ) ; // Wait for the requestAnimationFrame to run
23
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
24
24
25
25
expect ( create ) . toHaveBeenCalledWith (
26
26
expect . objectContaining ( {
44
44
</gradio-requirements>
45
45
</gradio-lite>
46
46
` ;
47
- await delay ( ) ; // Wait for the requestAnimationFrame to run
47
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
48
48
49
49
expect ( create ) . toHaveBeenCalledWith (
50
50
expect . objectContaining ( {
75
75
</gradio-requirements>
76
76
</gradio-lite>
77
77
` ;
78
- await delay ( ) ; // Wait for the requestAnimationFrame to run
78
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
79
79
80
80
expect ( create ) . toHaveBeenCalledWith (
81
81
expect . objectContaining ( {
@@ -100,7 +100,7 @@ scipy
100
100
import gradio as gr
101
101
</gradio-lite>
102
102
` ;
103
- await delay ( ) ; // Wait for the requestAnimationFrame to run
103
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
104
104
105
105
expect ( create ) . toHaveBeenCalledWith (
106
106
expect . objectContaining ( {
@@ -119,7 +119,7 @@ scipy
119
119
</gradio-code>
120
120
</gradio-lite>
121
121
` ;
122
- await delay ( ) ; // Wait for the requestAnimationFrame to run
122
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
123
123
124
124
expect ( create ) . toHaveBeenCalledWith (
125
125
expect . objectContaining ( {
@@ -149,7 +149,7 @@ scipy
149
149
</gradio-file>
150
150
</gradio-lite>
151
151
` ;
152
- await delay ( ) ; // Wait for the requestAnimationFrame to run
152
+ await awaitAnimationFrame ( ) ; // Wait for `create` to be called in the ` requestAnimationFrame` callback
153
153
154
154
expect ( create ) . toHaveBeenCalledWith (
155
155
expect . objectContaining ( {
0 commit comments