@@ -186,15 +186,11 @@ class Test {
186
186
* value when calling ``func``. Defaults to the :js:class:`Test` object.
187
187
*/
188
188
public step_func ( func : UnknownFunc , this_obj ?: object ) : UnknownFunc {
189
- const test_this = this ;
190
-
191
189
if ( arguments . length === 1 ) {
192
190
this_obj = this ;
193
191
}
194
192
195
- return function ( ...params : unknown [ ] ) {
196
- return test_this . step . call ( test_this , func , this_obj , ...params ) ;
197
- } ;
193
+ return ( ...params : unknown [ ] ) => this . step ( func , this_obj , ...params ) ;
198
194
}
199
195
200
196
/**
@@ -210,18 +206,16 @@ class Test {
210
206
* value when calling `func`. Defaults to the :js:class:`Test` object.
211
207
*/
212
208
public step_func_done ( func ?: UnknownFunc , this_obj ?: object ) : UnknownFunc {
213
- const test_this = this ;
214
-
215
209
if ( arguments . length === 1 ) {
216
- this_obj = test_this ;
210
+ this_obj = this ;
217
211
}
218
212
219
- return function ( ...params : unknown [ ] ) {
213
+ return ( ...params : unknown [ ] ) => {
220
214
if ( func ) {
221
- test_this . step . call ( test_this , func , this_obj , ...params ) ;
215
+ this . step ( func , this_obj , ...params ) ;
222
216
}
223
217
224
- test_this . done ( ) ;
218
+ this . done ( ) ;
225
219
} ;
226
220
}
227
221
@@ -257,12 +251,8 @@ class Test {
257
251
timeout : number ,
258
252
...rest : unknown [ ]
259
253
) : ReturnType < typeof setTimeout > {
260
- const test_this = this ;
261
-
262
254
return setTimeout (
263
- this . step_func ( function ( ) {
264
- return func . call ( test_this , ...rest ) ;
265
- } ) ,
255
+ this . step_func ( ( ) => func ( ...rest ) ) ,
266
256
timeout
267
257
) ;
268
258
}
@@ -439,6 +429,13 @@ declare global {
439
429
properties ?: unknown
440
430
) : void ;
441
431
function async_test ( func : TestFn , name : string , properties ?: unknown ) : void ;
432
+
433
+ function step_timeout (
434
+ func : UnknownFunc ,
435
+ timeout : number ,
436
+ ...rest : unknown [ ]
437
+ ) : ReturnType < typeof setTimeout > ;
438
+
442
439
function assert_equals ( a : unknown , b : unknown , message ?: string ) : void ;
443
440
function assert_not_equals ( a : unknown , b : unknown , message ?: string ) : void ;
444
441
function assert_true ( val : unknown , message ?: string ) : void ;
@@ -737,6 +734,22 @@ globalThis.test = (func, name, properties): void => {
737
734
}
738
735
} ;
739
736
737
+ /**
738
+ * Global version of :js:func:`Test.step_timeout` for use in single page tests.
739
+ *
740
+ * @param func - Function to run after the timeout
741
+ * @param timeout - Time in ms to wait before running the
742
+ * test step. The actual wait time is ``timeout`` x
743
+ * ``timeout_multiplier``.
744
+ */
745
+ globalThis . step_timeout = (
746
+ func : UnknownFunc ,
747
+ timeout : number ,
748
+ ...rest : unknown [ ]
749
+ ) : ReturnType < typeof setTimeout > => {
750
+ return setTimeout ( ( ) => func ( ...rest ) , timeout ) ;
751
+ } ;
752
+
740
753
globalThis . assert_equals = ( a , b , message ) : void => {
741
754
strictEqual ( a , b , message ) ;
742
755
} ;
0 commit comments