Skip to content

Add doNotFake for vi.useFakeTimers #6498

@ailandini-accenture

Description

@ailandini-accenture

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions