Skip to content

Fake timers support for tests #1283

@jsartisan

Description

@jsartisan

Is there a way to use fakeTimers in sandpack's tests component?

Currently I am forced to use realTimers. It works but it takes a long time to see the tests results ( because of real timers ofcourse ). The way I am writing tests is using a "wait" utility

import { debounce } from "./index";

function wait(time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}

describe("Debounce Function", () => {
  it("should not be invoked immediately", async () => {
    const originalFunction1 = jest.fn();
    const debouncedFunction1 = debounce(originalFunction1, 300);
    debouncedFunction1();
    expect(originalFunction1).not.toBeCalled();
  });
});

Is there a better way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew issues that needs consideration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions