fix: save methods of children Date instance (#437)
Fix issue #437 by creating ClockDate as JS class and extending it from NativeDate
Why I did this way:
- In initinial solution (creating
ClockDateby JS function)ClockDatecan'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()withoutnewkeyword I solved by usingProxyinstance. - Also in my solution removed an
mirrorDatePropertiesfunction. 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.prototypenever equals toDate.prototype, becauseClockDateis extended fromDate - Please, check the other tests, that I changed. Hope, I changed them correct
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 😄
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.
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.
@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.
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.
As soon as this was out someone found an issue: #504
Basically, new dates do not pass the mustard.
What could be done to get the instanceof passing? I guess we cannot get the arrow to go both ways ... 😢
What could be done to get the instanceof passing?
We override Symbol.hasInstance I guess
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance
Ooh, you learn something every day! Programmable instanceof, that's some cool shit 😄 I'll create a fix asap.
Worked like a charm, thanks, Ben! https://github.com/sinonjs/fake-timers/pull/505