mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-17 17:10:03 +01:00
19 lines
436 B
TypeScript
19 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));
|
||
|
}
|