Skip to content
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
2 changes: 2 additions & 0 deletions exercises/02.test-structure/04.solution.hooks/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Then, I go to the `greet.test.ts` and add the `beforeAll()` hook that patches th

<CodeFile file="greet.test.ts" range="3-9" highlight="3,6-8" />

<callout-warning>I recommend providing an entire UTC date, including an explicit timezone, as the value of the mocked date to have a resilient test setup: `new OriginalDate('2024-01-01 00:00:00.000Z')`</callout-warning>
Copy link

Choose a reason for hiding this comment

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

That's a great addition for folks in other timezones @kettanaito!

One interesting thing although, I tested it here setting to new OriginalDate('2024-01-01 00:00:00.000Z') and it didn't work (Still getting Sunday), but when using new OriginalDate('2024-01-01 00:00:00.000') (without the Z) it worked.

I guess it's because it sets a UTC timezone, but the greet function still displays time in the Local Timezone, which means that it converts the timezone from UTC to local.

console.log(new Date('2024-01-01 00:00:00.000Z'))
// Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time)

console.log(new Date('2024-01-01 00:00:00.000'))
// Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time)
```


Similarly, I make sure to clean up this `Date` mock in the `afterAll()` hook:

<CodeFile file="greet.test.ts" range="11-13" highlight="12" />
Expand Down
Loading