File: timeout.js

package info (click to toggle)
htmx 4.0.0-alpha6-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 117,328 kB
  • sloc: javascript: 49,403; sh: 29; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 972 bytes parent folder | download | duplicates (2)
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
describe('timeout() unit tests', function() {

    it('returns promise that resolves after milliseconds', async function () {
        let start = Date.now()
        await htmx.timeout(50)
        let elapsed = Date.now() - start
        assert.isAtLeast(elapsed, 45)
    })

    it('accepts string time format', async function () {
        let start = Date.now()
        await htmx.timeout('50ms')
        let elapsed = Date.now() - start
        assert.isAtLeast(elapsed, 45)
    })

    it('accepts seconds format', async function () {
        let start = Date.now()
        await htmx.timeout('0.05s')
        let elapsed = Date.now() - start
        assert.isAtLeast(elapsed, 45)
    })

    it('returns undefined for zero time', function () {
        let result = htmx.timeout(0)
        assert.isUndefined(result)
    })

    it('returns undefined for negative time', function () {
        let result = htmx.timeout(-1)
        assert.isUndefined(result)
    })

});