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
804 stars 106 forks source link

feat: add RelativeTimeFormat to Intl API #479

Closed sebastinez closed 12 months ago

sebastinez commented 1 year ago

Purpose (TL;DR) - mandatory

PR #474 has introduced a mock for the intl API, and this has introduced a regression for me, where I'm not able to call Intl.RelativeTimeFormat.

Background (Problem in detail)

The problem showed in some of my test cases, once I updated fake-timers, when trying to use Intl.RelativeTimeFormat I got the following error: Intl.RelativeTimeFormat is not a constructor

Solution

The solution I opted for is to assign RelativeTimeFormat to the mocked Intl API with.

ClockIntl.RelativeTimeFormat = NativeIntl.RelativeTimeFormat;
codecov[bot] commented 1 year ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (fc312b9) 96.47% compared to head (d09e29c) 96.48%.

:exclamation: Current head d09e29c differs from pull request most recent head d4e78f2. Consider uploading reports for the commit d4e78f2 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #479 +/- ## ========================================== + Coverage 96.47% 96.48% +0.01% ========================================== Files 2 2 Lines 680 682 +2 ========================================== + Hits 656 658 +2 Misses 24 24 ``` | [Flag](https://app.codecov.io/gh/sinonjs/fake-timers/pull/479/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/sinonjs/fake-timers/pull/479/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) | `96.48% <100.00%> (+0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/sinonjs/fake-timers/pull/479?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) | Coverage Δ | | |---|---|---| | [src/fake-timers-src.js](https://app.codecov.io/gh/sinonjs/fake-timers/pull/479?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs#diff-c3JjL2Zha2UtdGltZXJzLXNyYy5qcw==) | `96.50% <100.00%> (+0.01%)` | :arrow_up: |

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

sebastinez commented 1 year ago

Thanks for your reviews, what are the next steps? Do you need me to sign something or can the PR get merged?

sebastinez commented 1 year ago

Hey folks, this issue doesn't allow me to update fake-timers, since it would break my production. Is there work be done on a better solution? Or is anything holding this PR up?

sebastinez commented 1 year ago

Didn't want to close the PR, just comment on it

fatso83 commented 1 year ago

Seems like you just need to implement your own suggestion that iterates over the props 🤩

PS. Nothing should ever prevent you from upgrading. Try the Npm package 'patch-package' next time ✌️

SimenB commented 1 year ago

Since there's no compilation step in this repo, you can also depend on your fork directly

piotrpalek commented 11 months ago

I'm getting the same issue, but with Intl.NumberFormat :( I think sinon would need to pick up the whole Intl API to fix this

edit: ok.. now I see this is actually doing that, so I probably need to wait for a release to happen?

fatso83 commented 11 months ago

New version is out.

piotrpalek commented 11 months ago

Thanks! Sorry for hijacking this PR 😅