1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/test-utils/use-fake-time.ts
Sebastian Malton c658a0b0da Get terminal tests to pass again
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-01-10 15:18:13 -05:00

25 lines
647 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { act } from "@testing-library/react";
let usingFakeTime = false;
export const advanceFakeTime = (milliseconds: number) => {
if (!usingFakeTime) {
throw new Error("Tried to advance fake time but it was not enabled. Call useFakeTime() first.");
}
act(() => {
jest.advanceTimersByTime(milliseconds);
});
};
export const testUsingFakeTime = (dateTime = "2015-10-21T07:28:00Z") => {
usingFakeTime = true;
jest.useFakeTimers();
jest.setSystemTime(new Date(dateTime));
};