-
Notifications
You must be signed in to change notification settings - Fork 5
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
02/04 - Mocked date gives wrong day if time not explicitly set to be after 00:00 #14
Comments
Hi, @isimmons. Thanks for sharing this! I've encountered a similar issue when giving the live version of this workshop, where the culprit was the omission of the explicit locale when calling
I'm trying to reproduce your issue, this is where I got: --- a/exercises/02.test-structure/04.solution.hooks/greet.test.ts
+++ b/exercises/02.test-structure/04.solution.hooks/greet.test.ts
@@ -6,6 +6,8 @@ beforeAll(() => {
globalThis.Date = new Proxy(globalThis.Date, {
construct: () => new OriginalDate('2024-01-01'),
})
+
+ console.log(new OriginalDate('2024-01-01'))
})
afterAll(() => { This prints the following for me:
Does this print 2023-12-31 for you? |
Yes Sir, here is my output. const date = new OriginalDate('2024-01-01')
console.log(date) // 2024-01-01T00:00:00.000Z
console.log(date.toLocaleDateString()) // 12/31/2023
console.log(date.toLocaleDateString('en-US', { weekday: 'long' })) // Sunday
const anotherDate = new OriginalDate('2024-01-01:00:00:00.001')
console.log(anotherDate) // 2024-01-01T00:00:00.001Z
console.log(anotherDate.toLocaleDateString()) // 1/1/2024
console.log(anotherDate.toLocaleDateString('en-US', { weekday: 'long' })) // Monday |
In exercise 02 section 04 "Hooks" my test failed. When mocking the date it appears to be defaulting to "2024-01-01:00:00" but the day doesn't actually start until 1 second after that so what I get is "2023-12-31" if I console.log it out.
I fixed it in my code by explicitly setting the time to 1AM
I just realized this is a problem on every lesson after this one. Is it something wrong on my end?
Windows 10, node 20
The text was updated successfully, but these errors were encountered: