| 1 | describe('timeout() unit tests', function() { |
| 2 | |
| 3 | it('returns promise that resolves after milliseconds', async function () { |
| 4 | let start = Date.now() |
| 5 | await htmx.timeout(50) |
| 6 | let elapsed = Date.now() - start |
| 7 | assert.isAtLeast(elapsed, 45) |
| 8 | }) |
| 9 | |
| 10 | it('accepts string time format', async function () { |
| 11 | let start = Date.now() |
| 12 | await htmx.timeout('50ms') |
| 13 | let elapsed = Date.now() - start |
| 14 | assert.isAtLeast(elapsed, 45) |
| 15 | }) |
| 16 | |
| 17 | it('accepts seconds format', async function () { |
| 18 | let start = Date.now() |
| 19 | await htmx.timeout('0.05s') |
| 20 | let elapsed = Date.now() - start |
| 21 | assert.isAtLeast(elapsed, 45) |
| 22 | }) |
| 23 | |
| 24 | it('returns undefined for zero time', function () { |
| 25 | let result = htmx.timeout(0) |
| 26 | assert.isUndefined(result) |
| 27 | }) |
| 28 | |
| 29 | it('returns undefined for negative time', function () { |
| 30 | let result = htmx.timeout(-1) |
| 31 | assert.isUndefined(result) |
| 32 | }) |
| 33 | |
| 34 | }); |