forked from testing-library/react-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-hooks.js
46 lines (34 loc) · 1004 Bytes
/
react-hooks.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
46
import {testHook, cleanup} from 'react-testing-library'
import useCounter from '../react-hooks'
afterEach(cleanup)
test('accepts default initial values', () => {
let count
testHook(() => ({count} = useCounter()))
expect(count).toBe(0)
})
test('accepts a default initial value for `count`', () => {
let count
testHook(() => ({count} = useCounter({})))
expect(count).toBe(0)
})
test('provides an `increment` function', () => {
let count, increment
testHook(() => ({count, increment} = useCounter({step: 2})))
expect(count).toBe(0)
increment()
expect(count).toBe(2)
})
test('provides an `decrement` function', () => {
let count, decrement
testHook(() => ({count, decrement} = useCounter({step: 2})))
expect(count).toBe(0)
decrement()
expect(count).toBe(-2)
})
test('accepts a default initial value for `step`', () => {
let count, increment
testHook(() => ({count, increment} = useCounter({})))
expect(count).toBe(0)
increment()
expect(count).toBe(1)
})