sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
806 stars 107 forks source link

`Date()` should return a string, not an object, in Lolex v4.1.0 #246

Closed moll closed 5 years ago

moll commented 5 years ago

Hey,

I believe Lolex deviates from the JavaScript standard behavior with regards to what Date() returns. I noticed this through a bug in my code that passed all tests, yet failed in production: I was creating a new date without newDate(2015, 5, 18). In tests, that was equivalent to new Date(..), but without mocking, it returns the current time as a string — an entirely different result. It seems to be an issue already since the times of Sinon v1.17.7 and possibly earlier. Here's an example from RunKit https://runkit.com/embed/delfomea61tm with Lolex v4.1.

require("lolex").install()
Date(2015, 5, 18) // => Thu Jun 18 2015 00:00:00 GMT+0000 (Coordinated Universal Time)
fatso83 commented 5 years ago

Verified! The standard is strange :)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

moll commented 5 years ago

I think the stale bot is too eager here.