1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Introduce helper for advancing fake time

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-07-01 09:57:35 +03:00
parent 3480b517c1
commit c11ac4e2bc
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A

View File

@ -0,0 +1,25 @@
/**
* 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 useFakeTime = (dateTime: string) => {
usingFakeTime = true;
jest.useFakeTimers();
jest.setSystemTime(new Date(dateTime));
};