Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function countUpFromTime(countFrom, id) {
const now = new Date();

// Validate date
const isValidDate = !isNaN(countFromDate.getTime());
const isValidDate = !Number.isNaN(countFromDate.getTime());

// Get DOM element
const idEl = document.getElementById(id);
Expand Down
4 changes: 2 additions & 2 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ h2 {
font-size: 2.5em;
font-weight: 700;
padding: 3rem;
color: #3cbaf2;
color: #2196F3;
background-color: #0ff;
background-color: rgba(0, 0, 0, .5);
text-align: center;
Expand Down Expand Up @@ -74,7 +74,7 @@ h2 {
gap: 20px;
text-align: center;
margin: 0 auto;
color: #3cbaf2;
color: #2196F3;
background-color: rgba(0, 0, 0, .5);
padding: 20px;
max-width: 90%;
Expand Down
14 changes: 14 additions & 0 deletions tests/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ describe('countUpFromTime', () => {
expect(Number(mockEl.hours.innerHTML)).toBeGreaterThanOrEqual(0);
});

test('covers for-loop else branch (break) when remainingDays < daysInYear', () => {
// Freeze time to a known date so the loop runs exactly once and hits the else branch
jest.useFakeTimers();
jest.setSystemTime(new Date('Nov 01, 2025 12:00:00'));
const mockEl = createMockDOM();
global.document.getElementById = jest.fn(() => mockEl);
// Choose a date in the previous year but with remaining days less than a full year
script.countUpFromTime('Dec 31, 2024 00:00:00', 'countup1');
// The function should have written numeric values to the DOM
expect(Number(mockEl.years.innerHTML)).toBeGreaterThanOrEqual(0);
expect(Number(mockEl.days.innerHTML)).toBeGreaterThanOrEqual(0);
jest.useRealTimers();
});

test('updates DOM elements with correct values', () => {
jest.useFakeTimers();
jest.setSystemTime(new Date('Sep 13, 2025 11:59:00'));
Expand Down