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> * Introduce reactive now to kludge around global shared state in library Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Replace all usages of "now" from mobx-utils with our own kludge to get rid of shared global state between unit tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate all usages of advanceTimersByTime to make sure things happening based on timers are run correctly Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix incorrect expect in test Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Enable skipped unit test since prerequisites are done Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
26 lines
625 B
TypeScript
26 lines
625 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 useFakeTime = (dateTime: string) => {
|
|
usingFakeTime = true;
|
|
|
|
jest.useFakeTimers();
|
|
|
|
jest.setSystemTime(new Date(dateTime));
|
|
};
|