Files

25 lines
545 B
JavaScript
Raw Permalink Normal View History

2023-09-14 10:36:27 -04:00
/**
2023-10-06 09:46:54 -04:00
* Unit tests for src/wait.js
2023-09-14 10:36:27 -04:00
*/
2024-11-15 12:30:35 -05:00
import { wait } from '../src/wait.js'
2023-09-14 10:36:27 -04:00
2023-11-07 09:33:16 -05:00
describe('wait.js', () => {
2024-11-15 12:30:35 -05:00
it('Throws an invalid number', async () => {
2023-09-14 10:36:27 -04:00
const input = parseInt('foo', 10)
2024-11-15 12:30:35 -05:00
2023-09-14 10:36:27 -04:00
expect(isNaN(input)).toBe(true)
2024-11-15 12:30:35 -05:00
await expect(wait(input)).rejects.toThrow('milliseconds is not a number')
2023-09-14 10:36:27 -04:00
})
2024-11-15 12:30:35 -05:00
it('Waits with a valid number', async () => {
2023-09-14 10:36:27 -04:00
const start = new Date()
await wait(500)
const end = new Date()
const delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
})
})