fix: accept duck-typed TemporalDuration when Temporal absent from global#574
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes tick()/tickAsync()/jump() handling of Temporal.Duration-like (duck-typed) inputs when Temporal is not available on the faked global, preventing those values from falling through to parseTime() and throwing a confusing str.split is not a function.
Changes:
- Remove the
isPresent.Temporalgate from the duck-type.total()check intickValueToMs. - Update
durationToMsto omitrelativeTowhenNativeTemporalis unavailable. - Add a regression test for ticking with a TemporalDuration-shaped object in a Temporal-free global.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/fake-timers-src.js |
Accept duck-typed durations independent of Temporal presence; make relativeTo conditional on NativeTemporal. |
test/fake-timers-test.js |
Adds a regression test for duck-typed TemporalDuration inputs when Temporal is absent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+6641
to
+6648
| it("tick() accepts a TemporalDuration-shaped object even when Temporal is absent from the global", function () { | ||
| const clock = FakeTimers.createClock(0); | ||
| // duck-typed Duration: total("millisecond") returns ms, no native Temporal required | ||
| const duration = { | ||
| total: ({ unit }) => (unit === "millisecond" ? 5000 : 5), | ||
| }; | ||
| clock.tick(duration); | ||
| assert.equals(clock.now, 5000); |
|
|
||
| it("tick() accepts a TemporalDuration-shaped object even when Temporal is absent from the global", function () { | ||
| const clock = FakeTimers.createClock(0); | ||
| // duck-typed Duration: total("millisecond") returns ms, no native Temporal required |
fatso83
approved these changes
May 5, 2026
Contributor
|
agh, clumsy tired fingers. I was too trigger happy. I saw this might have pending changes. Just re-open and issue a revert on my merge if you need to (if you wanted to address something else) This is my sign to tuck in. God natt 💤 |
Member
Author
|
I'll take a look tomorrow. Natta 😀 |
This was referenced May 5, 2026
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I tried to use the new
Temporalstuff in Jest, and hit this 😀tickValueToMsgated theDurationduck-type check behindisPresent.Temporal, so any object with a.total()method fell through toparseTime()and threwTypeError: str.split is not a functionwhen Temporal was absent from the faked global.The guard doesn't belong here. Accepting a Duration as input to
tick()is purely duck-typed -durationToMsjust callsduration.total(...), it has no dependency on the native Temporal global. TheisPresent.Temporalguard is correct for fakingTemporal.Now.*(which has to construct real Temporal objects as return values), not for accepting input.Two changes:
isPresent.Temporal &&from the duck-type check intickValueToMsdurationToMsomitrelativeTowhenNativeTemporalis unavailable — calendar-unit durations will throw from within.total()itself, which is the right place for that errortick(),tickAsync(), andjump()all go throughtickValueToMsso all three get the fix.