@@ -16,14 +16,20 @@ describe('useCountdownClock', () => {
16
16
const now = Date . now ( ) / 1000
17
17
const tenSecondsFromNow = now + 10
18
18
const { result } = renderHook ( ( ) => useCountdownClock ( tenSecondsFromNow ) )
19
- expect ( result . current ) . toEqual ( '0d 0h 0m 10s' )
19
+ expect ( result . current ) . toEqual ( {
20
+ remainingTimeText : '0d 0h 0m 10s' ,
21
+ secondsRemaining : 10 ,
22
+ } )
20
23
} )
21
24
it ( 'updates every second' , ( ) => {
22
25
const now = Date . now ( ) / 1000
23
26
const tenSecondsFromNow = now + 10
24
27
const { result } = renderHook ( ( ) => useCountdownClock ( tenSecondsFromNow ) )
25
28
for ( let i = 10 ; i >= 0 ; i -- ) {
26
- expect ( result . current ) . toEqual ( `0d 0h 0m ${ i } s` )
29
+ expect ( result . current ) . toEqual ( {
30
+ remainingTimeText : `0d 0h 0m ${ i } s` ,
31
+ secondsRemaining : i ,
32
+ } )
27
33
act ( ( ) => jest . advanceTimersByTime ( 1000 ) )
28
34
}
29
35
} )
@@ -32,7 +38,10 @@ describe('useCountdownClock', () => {
32
38
const now = Date . now ( ) / 1000
33
39
const tenSecondsAgo = now - 10
34
40
const { result } = renderHook ( ( ) => useCountdownClock ( tenSecondsAgo ) )
35
- expect ( result . current ) . toEqual ( '0d 0h 0m 0s' )
41
+ expect ( result . current ) . toEqual ( {
42
+ remainingTimeText : '0d 0h 0m 0s' ,
43
+ secondsRemaining : 0 ,
44
+ } )
36
45
} )
37
46
38
47
test ( 'timer is cleared on unmount' , ( ) => {
@@ -41,15 +50,24 @@ describe('useCountdownClock', () => {
41
50
const { result, unmount } = renderHook ( ( ) =>
42
51
useCountdownClock ( tenSecondsFromNow ) ,
43
52
)
44
- expect ( result . current ) . toEqual ( '0d 0h 0m 10s' )
53
+ expect ( result . current ) . toEqual ( {
54
+ remainingTimeText : '0d 0h 0m 10s' ,
55
+ secondsRemaining : 10 ,
56
+ } )
45
57
act ( ( ) => {
46
58
jest . advanceTimersByTime ( 1000 )
47
59
} )
48
- expect ( result . current ) . toEqual ( '0d 0h 0m 9s' )
60
+ expect ( result . current ) . toEqual ( {
61
+ remainingTimeText : '0d 0h 0m 9s' ,
62
+ secondsRemaining : 9 ,
63
+ } )
49
64
unmount ( )
50
65
act ( ( ) => {
51
66
jest . advanceTimersByTime ( 1000 )
52
67
} )
53
- expect ( result . current ) . toEqual ( '0d 0h 0m 9s' )
68
+ expect ( result . current ) . toEqual ( {
69
+ remainingTimeText : '0d 0h 0m 9s' ,
70
+ secondsRemaining : 9 ,
71
+ } )
54
72
} )
55
73
} )
0 commit comments