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:
parent
3480b517c1
commit
c11ac4e2bc
25
src/common/test-utils/use-fake-time.ts
Normal file
25
src/common/test-utils/use-fake-time.ts
Normal 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));
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user