Files
UT-Registration-Plus/src/shared/util/tests/time.test.ts
2025-03-24 02:28:41 -05:00

16 lines
575 B
TypeScript

import { sleep } from '@shared/util/time';
import { describe, expect, it } from 'vitest';
describe('sleep', () => {
it('should resolve after the specified number of milliseconds', async () => {
const start = performance.now();
const milliseconds = 1000;
await sleep(milliseconds);
const end = performance.now();
const elapsed = end - start;
// Flaky test due to JS's lack of precision in setTimeout,
// so we allow for a 1ms difference
expect(elapsed).toBeGreaterThanOrEqual(milliseconds - 1);
});
});