File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function countUpFromTime(countFrom, id) {
1010 const now = new Date ( ) ;
1111
1212 // Validate date
13- const isValidDate = ! isNaN ( countFromDate . getTime ( ) ) ;
13+ const isValidDate = ! Number . isNaN ( countFromDate . getTime ( ) ) ;
1414
1515 // Get DOM element
1616 const idEl = document . getElementById ( id ) ;
Original file line number Diff line number Diff line change 2525 font-size : 2.5em ;
2626 font-weight : 700 ;
2727 padding : 3rem ;
28- color : # 3cbaf2 ;
28+ color : # 2196F3 ;
2929 background-color : # 0ff ;
3030 background-color : rgba (0 , 0 , 0 , .5 );
3131 text-align : center;
7474 gap : 20px ;
7575 text-align : center;
7676 margin : 0 auto;
77- color : # 3cbaf2 ;
77+ color : # 2196F3 ;
7878 background-color : rgba (0 , 0 , 0 , .5 );
7979 padding : 20px ;
8080 max-width : 90% ;
Original file line number Diff line number Diff line change @@ -169,6 +169,20 @@ describe('countUpFromTime', () => {
169169 expect ( Number ( mockEl . hours . innerHTML ) ) . toBeGreaterThanOrEqual ( 0 ) ;
170170 } ) ;
171171
172+ test ( 'covers for-loop else branch (break) when remainingDays < daysInYear' , ( ) => {
173+ // Freeze time to a known date so the loop runs exactly once and hits the else branch
174+ jest . useFakeTimers ( ) ;
175+ jest . setSystemTime ( new Date ( 'Nov 01, 2025 12:00:00' ) ) ;
176+ const mockEl = createMockDOM ( ) ;
177+ global . document . getElementById = jest . fn ( ( ) => mockEl ) ;
178+ // Choose a date in the previous year but with remaining days less than a full year
179+ script . countUpFromTime ( 'Dec 31, 2024 00:00:00' , 'countup1' ) ;
180+ // The function should have written numeric values to the DOM
181+ expect ( Number ( mockEl . years . innerHTML ) ) . toBeGreaterThanOrEqual ( 0 ) ;
182+ expect ( Number ( mockEl . days . innerHTML ) ) . toBeGreaterThanOrEqual ( 0 ) ;
183+ jest . useRealTimers ( ) ;
184+ } ) ;
185+
172186 test ( 'updates DOM elements with correct values' , ( ) => {
173187 jest . useFakeTimers ( ) ;
174188 jest . setSystemTime ( new Date ( 'Sep 13, 2025 11:59:00' ) ) ;
You can’t perform that action at this time.
0 commit comments