mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-13 07:00:04 +01:00
18 lines
436 B
TypeScript
18 lines
436 B
TypeScript
export function mockDateNow(initialDateNow: number): void {
|
|
beforeAll(() => {
|
|
vi.useFakeTimers().setSystemTime(initialDateNow);
|
|
});
|
|
|
|
afterAll(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Mocks `Math.random` to return a static value.
|
|
*/
|
|
export function mockRandom(staticValue = 0.5) {
|
|
const realRandom = Math.random;
|
|
beforeEach(() => (Math.random = () => staticValue));
|
|
afterEach(() => (Math.random = realRandom));
|
|
}
|