This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwait.test.js
More file actions
47 lines (42 loc) · 1.2 KB
/
Copy pathwait.test.js
File metadata and controls
47 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Unit tests for the wait utility function.
*/
import wait from '../../src/util/wait.js'
describe('wait', () => {
/**
* Test basic functionality
*/
describe('basic functionality', () => {
/**
* Test that wait resolves after the specified time.
*/
test('should resolve after specified milliseconds', async () => {
const startTime = Date.now()
const delay = 100
const result = await wait(delay)
const elapsed = Date.now() - startTime
expect(result).toBe('done!')
expect(elapsed).toBeGreaterThanOrEqual(delay)
// Allow 50ms buffer for timing variations in the JavaScript runtime
expect(elapsed).toBeLessThan(delay + 50)
})
/**
* Test that wait handles zero milliseconds.
*/
test('should handle zero milliseconds', async () => {
const result = await wait(0)
expect(result).toBe('done!')
})
})
/**
* Test error handling
*/
describe('error handling', () => {
/**
* Test that wait throws error for non-number input.
*/
test('should throw error for non-number input', async () => {
await expect(wait('invalid')).rejects.toThrow('milliseconds not a number')
})
})
})