mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 10:54:44 +00:00
feat(packages/stdlib): add sleep async util
This commit is contained in:
19
packages/stdlib/src/async/sleep/index.test.ts
Normal file
19
packages/stdlib/src/async/sleep/index.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
||||
import { sleep } from '.';
|
||||
|
||||
describe('sleep', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({ shouldAdvanceTime: true });
|
||||
});
|
||||
|
||||
it('delay execution by the specified amount of time', async () => {
|
||||
const start = performance.now();
|
||||
const delay = 100;
|
||||
|
||||
await sleep(delay);
|
||||
|
||||
const end = performance.now();
|
||||
|
||||
expect(end - start).toBeGreaterThanOrEqual(delay);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user