-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
39 lines (29 loc) · 945 Bytes
/
index.test.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
import test from 'ava'
import sinon from 'sinon'
import { makeReduxDebouncer } from './index'
test('Call next', (t) => {
const next = sinon.spy()
const debouncer = makeReduxDebouncer({ type: 'foo' })
debouncer()(next)({ type: 'foo' })
t.true(next.callCount === 1)
})
test('Custom type with compare', (t) => {
const next = sinon.spy()
const debouncer = makeReduxDebouncer({
type: 'foo',
compare: (current, prev) => current.param === prev.param,
})
debouncer()(next)({ type: 'foo', param: 1 })
debouncer()(next)({ type: 'foo', param: 2 })
t.true(next.callCount === 2)
})
test('Custom type with compare & equals params', (t) => {
const next = sinon.spy()
const debouncer = makeReduxDebouncer({
type: 'foo',
compare: (current, prev) => current.param === prev.param,
})
debouncer()(next)({ type: 'foo', param: 1 })
debouncer()(next)({ type: 'foo', param: 1 })
t.true(next.callCount === 1)
})