From 42739c660e4aa304279c259f05dd712811d0a4b9 Mon Sep 17 00:00:00 2001 From: Cibiyanna26 Date: Tue, 25 Mar 2025 14:01:03 +0530 Subject: [PATCH] modifing yyy label, spy reset after each test gets finished --- src/lib/__tests__/charts.test.ts | 16 ++++++++++------ src/lib/charts.ts | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/__tests__/charts.test.ts b/src/lib/__tests__/charts.test.ts index 49e27c90..cd9e8651 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.ts index 8939b3c1..1fb329be 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; }