@@ -69,7 +69,7 @@ describe('useIdleTimer', () => {
6969 } , 500 )
7070 } )
7171
72- it ( 'Should pause on idle when stopOnIdle is set' , ( done ) => {
72+ it ( 'Should pause on idle when stopOnIdle is set' , done => {
7373 props . onIdle = sinon . spy ( )
7474 props . onActive = sinon . spy ( )
7575 props . timeout = 400
@@ -84,7 +84,7 @@ describe('useIdleTimer', () => {
8484 } , 500 )
8585 } )
8686
87- it ( 'Should start on reset() when stopOnIdle is set' , ( done ) => {
87+ it ( 'Should start on reset() when stopOnIdle is set' , done => {
8888 props . onIdle = sinon . spy ( )
8989 props . onActive = sinon . spy ( )
9090 props . timeout = 400
@@ -101,7 +101,7 @@ describe('useIdleTimer', () => {
101101 } , 500 )
102102 } )
103103
104- it ( 'Should go idle after reset() and user input when stopOnIdle is set' , ( done ) => {
104+ it ( 'Should go idle after reset() and user input when stopOnIdle is set' , done => {
105105 props . onIdle = sinon . spy ( )
106106 props . onActive = sinon . spy ( )
107107 props . timeout = 400
@@ -123,10 +123,26 @@ describe('useIdleTimer', () => {
123123 } , 500 )
124124 } , 500 )
125125 } )
126+
127+ it ( 'Should allow timeout to be changed dynamically' , done => {
128+ props . onIdle = sinon . spy ( )
129+ props . timeout = 500
130+ const { result, rerender } = idleTimer ( )
131+ setTimeout ( ( ) => {
132+ expect ( props . onIdle . callCount ) . toBe ( 1 )
133+ props . timeout = 300
134+ rerender ( )
135+ result . current . reset ( )
136+ setTimeout ( ( ) => {
137+ expect ( props . onIdle . callCount ) . toBe ( 2 )
138+ done ( )
139+ } , 400 )
140+ } , 600 )
141+ } )
126142 } )
127143
128144 describe ( 'events' , ( ) => {
129- it ( 'Should set custom events' , ( done ) => {
145+ it ( 'Should set custom events' , done => {
130146 props . onActive = sinon . spy ( )
131147 props . events = [ 'mousedown' ]
132148 props . timeout = 200
@@ -369,7 +385,7 @@ describe('useIdleTimer', () => {
369385 } )
370386
371387 describe ( 'getRemainingTime' , ( ) => {
372- it ( 'Should return 0 for remaining time while idle' , ( done ) => {
388+ it ( 'Should return 0 for remaining time while idle' , done => {
373389 props . timeout = 200
374390 const { result } = idleTimer ( )
375391 setTimeout ( ( ) => {
@@ -393,7 +409,7 @@ describe('useIdleTimer', () => {
393409 } )
394410
395411 describe ( 'getElapsedTime' , ( ) => {
396- it ( 'Should get the elapsed time' , ( done ) => {
412+ it ( 'Should get the elapsed time' , done => {
397413 const { result } = idleTimer ( )
398414 setTimeout ( ( ) => {
399415 // Accurate within 20ms
@@ -416,7 +432,7 @@ describe('useIdleTimer', () => {
416432 } )
417433
418434 describe ( 'isIdle' , ( ) => {
419- it ( 'Should get the idle state' , ( done ) => {
435+ it ( 'Should get the idle state' , done => {
420436 props . timeout = 200
421437 const { result } = idleTimer ( )
422438 expect ( result . current . isIdle ( ) ) . toBe ( false )
0 commit comments