Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
modifing yyy label, spy reset after each test gets finished
Cibiyanna2642739c660e4a
diff --git a/src/lib/__tests__/charts.test.ts b/src/lib/__tests__/charts.test.tsindex 49e27c909..cd9e86517 100644--- a/src/lib/__tests__/charts.test.ts+++ b/src/lib/__tests__/charts.test.ts@@ -41,19 +41,23 @@ describe('renderNumberLabels', () => {});});-// test for renderDateLabels--jest.spyOn(require('lib/date'), 'formatDate'); // Spy on formatDate but use real implementation-describe('renderDateLabels', () => {const mockValues = [{ value: '2024-03-23T10:00:00Z' }, { value: '2024-03-24T15:30:00Z' }];+ beforeEach(() => {+ jest.spyOn(require('lib/date'), 'formatDate');+ });++ afterEach(() => {+ jest.restoreAllMocks(); // Reset spy to prevent interference+ });+test.each([['minute', 'h:mm', 'en-US'],['hour', 'p', 'en-US'],['day', 'MMM d', 'en-US'],['month', 'MMM', 'en-US'],- ['year', 'YYY', 'en-US'],+ ['year', 'yyyy', 'en-US'],])('formats date correctly for unit: %s', (unit, expectedFormat, locale) => {const formatLabel = renderDateLabels(unit, locale);const formatted = formatLabel('label', 0, mockValues);@@ -67,7 +71,7 @@ describe('renderDateLabels', () => {expect(formatLabel('original-label', 0, mockValues)).toBe('original-label');});- test('handles invalid date gracefully', () => {+ test('throws error for invalid date input', () => {const invalidValues = [{ value: 'invalid-date' }];const formatLabel = renderDateLabels('day', 'en-US');diff --git a/src/lib/charts.ts b/src/lib/charts.tsindex 8939b3c1b..1fb329be5 100644--- a/src/lib/charts.ts+++ b/src/lib/charts.ts@@ -19,7 +19,7 @@ export function renderDateLabels(unit: string, locale: string) {case 'month':return formatDate(d, 'MMM', locale);case 'year':- return formatDate(d, 'YYY', locale);+ return formatDate(d, 'yyyy', locale);default:return label;}