mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
25 lines
647 B
TypeScript
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));
|
|
};
|