@@ -11,6 +11,8 @@ import {
1111 wait ,
1212} from '../src/api/time.ts' ;
1313
14+ const DELAY = 10 ;
15+
1416describe ( 'Stopper' , ( ) => {
1517 let stopper : Stopper ;
1618
@@ -19,7 +21,6 @@ describe('Stopper', () => {
1921 } ) ;
2022
2123 test ( 'start/stop' , async ( ) => {
22- const DELAY = 10 ;
2324 stopper . start ( ) ;
2425 await wait ( DELAY ) ;
2526 stopper . stop ( ) ;
@@ -34,7 +35,6 @@ describe('Stopper', () => {
3435 } ) ;
3536
3637 test ( 'elapsed continues counting after stop' , async ( ) => {
37- const DELAY = 10 ;
3838 stopper . start ( ) ;
3939 await wait ( DELAY ) ;
4040 stopper . stop ( ) ;
@@ -58,7 +58,6 @@ describe('Stopper', () => {
5858describe ( 'Timer - default options' , ( ) => {
5959 test ( 'start' , async ( ) => {
6060 let counter = 0 ;
61- const DELAY = 10 ;
6261 const timer = new Timer ( { delay : DELAY } , ( ) => {
6362 counter ++ ;
6463 } ) ;
@@ -73,7 +72,6 @@ describe('Timer - default options', () => {
7372
7473 test ( 'stop before expected' , async ( ) => {
7574 let counter = 0 ;
76- const DELAY = 10 ;
7775 const timer = new Timer ( { delay : 2 * DELAY } , ( ) => {
7876 counter ++ ;
7977 } ) ;
@@ -91,7 +89,6 @@ describe('Timer - default options', () => {
9189describe ( 'Timer - interval option' , ( ) => {
9290 test ( 'start/stop' , async ( ) => {
9391 let counter = 0 ;
94- const DELAY = 10 ;
9592 const interval = new Timer ( { delay : DELAY , repetitive : true } , ( ) => {
9693 counter ++ ;
9794 } ) ;
@@ -106,23 +103,27 @@ describe('Timer - interval option', () => {
106103
107104describe ( 'Timer - animation + measurable' , ( ) => {
108105 test ( 'start/stop' , async ( ) => {
109- const SECOND = 1e3 ;
110106 let count = 0 ;
111- const timer = new Timer ( { animation : true , measurable : true } , ( ) => {
107+ const TIMESPAN = 100 ;
108+ const timer = new Timer ( {
109+ animation : true ,
110+ repetitive : true ,
111+ measurable : true ,
112+ } , ( ) => {
112113 count ++ ;
113114 } ) ;
114115
115116 expect ( timer . isPending ( ) ) . toBe ( false ) ;
116-
117117 timer . start ( ) ;
118-
119118 expect ( timer . isPending ( ) ) . toBe ( true ) ;
120- await wait ( SECOND ) ;
119+
120+ await wait ( TIMESPAN ) ;
121121
122122 timer . stop ( ) ;
123123 expect ( timer . isPending ( ) ) . toBe ( false ) ;
124- expect ( timer . callbackSelfTime < 0.5 ) . toBe ( true ) ;
125- expect ( count ) . toBeLessThan ( 62 ) ;
124+ expect ( timer . callbackSelfTime ) . toBeLessThan ( 0.5 ) ;
125+ expect ( count ) . toBeGreaterThan ( 1 ) ;
126+ expect ( count ) . toBeLessThan ( TIMESPAN / ( 1e3 / 60 ) ) ;
126127 } ) ;
127128} ) ;
128129
@@ -174,4 +175,4 @@ describe('callableOnce', () => {
174175 } ) ;
175176} ) ;
176177
177- await wait ( 1e3 ) ;
178+ await wait ( 10 ) ;
0 commit comments