deno.land / x / rambda@v9.1.1 / source / debounce.spec.js

debounce.spec.js
نووسراو ببینە
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
import { debounce } from './debounce.js'import { delay } from './delay.js'
test('happy', async () => { let counter = 0 let aHolder
const inc = a => { aHolder = a counter++ } const incWrapped = debounce(inc, 500)
incWrapped(1) expect(counter).toBe(0)
await delay(200)
incWrapped(2) expect(counter).toBe(0)
await delay(700) expect(counter).toBe(1) expect(aHolder).toBe(2)})
test('immediate debounce', async () => { let counter = 0 const inc = () => { counter++ }
const incWrapped = debounce( inc, 500, true ) incWrapped() expect(counter).toBe(1) await delay(200) incWrapped() expect(counter).toBe(1) await delay(700) incWrapped() expect(counter).toBe(2)})
rambda

Version Info

Tagged at
2 months ago