Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doNotFake for vi.useFakeTimers #6498

Closed
4 tasks done
ailandini-accenture opened this issue Sep 13, 2024 · 2 comments
Closed
4 tasks done

Add doNotFake for vi.useFakeTimers #6498

ailandini-accenture opened this issue Sep 13, 2024 · 2 comments

Comments

@ailandini-accenture
Copy link

Clear and concise description of the problem

Currently, jest useFakeTimers has the option to pass { doNotFake: <SomeTimerFacet>} to prevent fake timers from faking specific apis/functions like setTimeOut etc.

vitest provides the toFake option where you can explicitly decide which apis and functions to mock, but for things like usage with msw v2 where we cannot fake queueMicrotask, but would like to fake everything else, this means I have to explicitly specify every other FakeMethod in toFake when using vi.useFakeTimers.

Suggested solution

Implement the doNotFake option so one can simply write vi.useFakeTimers({ doNotFake: queueMicrotask }) and get the desired result of faking every other FakeMethod

Alternative

Currently we just create a const with every other FakeMethod and pass it to toFake. This is a fine workaround, but not a satisfactory one as it's a large list.

Even just exporting the FakeMethod type would be a great help.

Additional context

No response

Validations

@ailandini-accenture
Copy link
Author

In hindsight, this may not apply to vitest at all.
Please close if irrelevant.

@sheremet-va
Copy link
Member

Vitest exposes fakeTimersDefaults from vitest/config. In the future, we won't specify toFake values, they will be implied from the environment: #6288 Then it will have doNotFake option.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants