Skip to content

Conversation

@Han5991
Copy link
Contributor

@Han5991 Han5991 commented May 22, 2025

Issue

Two test files were failing due to timezone-related issues:

  1. packages/@mantine/dates/src/components/Month/get-date-in-tab-order/get-date-in-tab-order.test.ts

    • Test case: returns current day
    • Expected: "2025-05-22" (UTC)
    • Received: "2025-05-23" (local KST)
  2. packages/@mantine/dates/src/components/Day/Day.test.tsx

    • Test case: adds data-today attribute if date is the same as today
    • Failed to find expected data-today attribute

Root Cause

The tests were using new Date().toISOString().split('T')[0] which returns dates in UTC. This caused failures when the local date (e.g., KST, UTC+9) was different from the UTC date. For example, when it's May 23 in KST, it's still May 22 in UTC.

Solution

  1. In get-date-in-tab-order.test.ts:

    • Updated the returns current day test to use dayjs().format('YYYY-MM-DD') for getting the current local date
    • Aligned the month parameter with the local date
  2. In Day.test.tsx:

    • Added dayjs import
    • Updated the test to use dayjs().format('YYYY-MM-DD') when passing the date prop to the Day component
  3. Code Style:

    • Ran Prettier to maintain consistent code formatting

Testing

  • All tests in both files now pass successfully
  • The components now correctly handle local dates in tests

Additional Notes

When writing tests that involve dates, it's important to be explicit about timezones. Using dayjs() without parameters ensures we're working with the local timezone, which is typically what we want for date component tests.

@rtivital rtivital merged commit beea3ec into mantinedev:master May 26, 2025
1 check passed
@rtivital
Copy link
Member

Thanks!

@Han5991 Han5991 deleted the feature/fix-testcode branch June 22, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants