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

Open
4 tasks done
ailandini-accenture opened this issue Sep 13, 2024 · 1 comment
Open
4 tasks done

Add doNotFake for vi.useFakeTimers #6498

ailandini-accenture opened this issue Sep 13, 2024 · 1 comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant