From a0f2416062d683dc26d46b44c75b698fa7b2bb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20M=C3=A4lman?= Date: Sat, 1 Nov 2025 00:16:09 +0100 Subject: [PATCH 1/2] Fix date validation check and update h2 color in CSS --- src/script.js | 2 +- src/style.css | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script.js b/src/script.js index bc14519..509ed6b 100644 --- a/src/script.js +++ b/src/script.js @@ -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); diff --git a/src/style.css b/src/style.css index b913d7c..8d4dbbc 100644 --- a/src/style.css +++ b/src/style.css @@ -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; @@ -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%; From 4d878e947bcde875d23795eec1eb6e116700db6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20M=C3=A4lman?= Date: Sat, 1 Nov 2025 00:45:48 +0100 Subject: [PATCH 2/2] Add test for for-loop else branch in countUpFromTime function --- tests/script.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/script.test.js b/tests/script.test.js index 8de1891..a2e327e 100644 --- a/tests/script.test.js +++ b/tests/script.test.js @@ -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'));