Skip to content

API for Mocking Globals with Isolation #524

@helloimalastair

Description

@helloimalastair

Hi y'all!

I wanted to ask, what is the stance of the team on providing a way to set mocks on global timing-related APIs that can be locked to a given scope? For example:

import FakeTimers from "@sinonjs/fake-timers";

const timer = FakeTimers.install({ toFake: ['Date'] });

function blockA() {
	return timer.useSystemTime(0, () => `Current timetstamp is ${Date.now()}`);
}

function blockB() {
	return `Current timetstamp is ${Date.now()}`;
}

// Run concurrently, blockA returns timestamp of 0,
// while blockB returns actual timestamp

This is related to vitest#5750

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions