fake-timers icon indicating copy to clipboard operation
fake-timers copied to clipboard

fix: save methods of children Date instance (#437)

Open Oustinger opened this issue 2 years ago • 3 comments

Fix issue #437 by creating ClockDate as JS class and extending it from NativeDate

Why I did this way:

  • In initinial solution (creating ClockDate by JS function) ClockDate can't be correct instance to extend from it. That's why I replaced function on class. And it resolved my problem.
  • Mechanics of call Date() without new keyword I solved by using Proxy instance.
  • Also in my solution removed an mirrorDateProperties function. It's not needed any more.

But I had some troubles with tests:

  • I skiped this test, because I didn't understand what it checks and how it should be now
  • I skiped an other test, because I think it's not corresponding for now. ClockDate.prototype never equals to Date.prototype, because ClockDate is extended from Date
  • Please, check the other tests, that I changed. Hope, I changed them correct

Oustinger avatar Sep 05 '23 10:09 Oustinger

Oooh, I somehow missed that this was added. Sorry about the late look, but while this is interesting, my head is a bit fried 🤯 This is quite a big change, so I (or someone else with a bigger head) needs to take a new look with a fresh head!

Thanks for providing a fix to something that bugged you a year ago. That's persistence we can appreciate 😄

fatso83 avatar Oct 05 '23 21:10 fatso83

It's a bit scary breaking change, so I think I would like some more 👀 on this before going ahead.

I started reviewing it and came to the "bit scary" conclusion as well.

benjamingr avatar Oct 06 '23 13:10 benjamingr

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.

stale[bot] avatar Dec 27 '23 10:12 stale[bot]

@Oustinger This is getting a bit old, but from the comments I see that I basically OK'd it. Any chance you can get it over the finish line? Was fine work.

fatso83 avatar Aug 15 '24 12:08 fatso83

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.53%. Comparing base (6f90a44) to head (35363ee). Report is 6 commits behind head on main.

Files Patch % Lines
src/fake-timers-src.js 81.25% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
- Coverage   97.56%   97.53%   -0.03%     
==========================================
  Files          16       17       +1     
  Lines        4430     4424       -6     
==========================================
- Hits         4322     4315       -7     
- Misses        108      109       +1     
Flag Coverage Δ
unit 97.53% <91.17%> (-0.03%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 24 '24 16:08 codecov[bot]

As soon as this was out someone found an issue: #504

Basically, new dates do not pass the mustard.

image

What could be done to get the instanceof passing? I guess we cannot get the arrow to go both ways ... 😢

fatso83 avatar Sep 13 '24 11:09 fatso83

What could be done to get the instanceof passing?

We override Symbol.hasInstance I guess

benjamingr avatar Sep 13 '24 13:09 benjamingr

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance

benjamingr avatar Sep 13 '24 13:09 benjamingr

Ooh, you learn something every day! Programmable instanceof, that's some cool shit 😄 I'll create a fix asap.

fatso83 avatar Sep 13 '24 13:09 fatso83

Worked like a charm, thanks, Ben! https://github.com/sinonjs/fake-timers/pull/505

fatso83 avatar Sep 13 '24 13:09 fatso83