Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🐛 Fix test assertion in datepicker tests #20188

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ describe(`${toEquivalentLocalTime.name}`, () => {
});

it("outputs the same YYYY-MM-DDTHH:mm:ss", () => {
timezoneMock.register("Etc/GMT+10");
const TEST_TIMEZONE_UTC_OFFSET_IN_MINUTES = 600; // corresponds to GMT+10
const TEST_UTC_TIMESTAMP = "2000-01-01T12:00:00Z";

const result = toEquivalentLocalTime(TEST_UTC_TIMESTAMP);

// Regardless of the timezone, the local time should be the same
expect(result?.toISOString().substring(0, 19)).toEqual(TEST_UTC_TIMESTAMP.substring(0, 19));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.toISOString() is always set to the UTC timezone, so this assertion would only work in a UTC timezone.

Instead, we can assert that toEquivalentLocalTime() has the expected timezone offset with Date.getTimezoneOffset() and that dayjs.format(), which outputs a local timezone, will have the same YYYY-MM-DDTHH:mm:ss value.

expect(dayjs(result).format().substring(0, 19)).toEqual(TEST_UTC_TIMESTAMP.substring(0, 19));
expect(result?.getTimezoneOffset()).toEqual(TEST_TIMEZONE_UTC_OFFSET_IN_MINUTES);
});

it("converts utc time to equivalent local time in PST", () => {
Expand Down