Fix formatDateString test (#11786)

This PR fixes a broken test that makes the CI crash.

This is due to the library `date-fns` which now doesn't use the word
"about" in its relative date formatting, if we're not precisely on minus
2 months, which can change for example today the 29th of April, where
the 29th of February doesn't exist.

So instead of using months and falling into hard to test cases, we use
days instead, which is an easy and predictable relative computation.
This commit is contained in:
Lucas Bordeau
2025-04-29 11:45:58 +02:00
committed by GitHub
parent 4833ee2914
commit fda793ced2
2 changed files with 4 additions and 16 deletions

View File

@ -28,14 +28,8 @@ describe('formatDateString', () => {
});
it('should format date as relative when displayFormat is set to RELATIVE', () => {
const mockDate = DateTime.now().minus({ months: 2 }).toISO();
const mockRelativeDate = 'about 2 months ago';
jest.mock('@/localization/utils/formatDateISOStringToRelativeDate', () => ({
formatDateISOStringToRelativeDate: jest
.fn()
.mockReturnValue(mockRelativeDate),
}));
const mockDate = DateTime.now().minus({ days: 2 }).toISO();
const mockRelativeDate = '2 days ago';
const result = formatDateString({
...defaultParams,

View File

@ -30,14 +30,8 @@ describe('formatDateTimeString', () => {
});
it('should format date as relative when displayFormat is RELATIVE', () => {
const mockDate = DateTime.now().minus({ months: 2 }).toISO();
const mockRelativeDate = 'about 2 months ago';
jest.mock('@/localization/utils/formatDateISOStringToRelativeDate', () => ({
formatDateISOStringToRelativeDate: jest
.fn()
.mockReturnValue(mockRelativeDate),
}));
const mockDate = DateTime.now().minus({ days: 2 }).toISO();
const mockRelativeDate = '2 days ago';
const result = formatDateTimeString({
...defaultParams,