forked from reduxjs/react-redux
/
useRedux.spec.js
41 lines (34 loc) · 1012 Bytes
/
useRedux.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
/*eslint-disable react/display-name*/
/*eslint-disable react/prop-types*/
import React from 'react'
import { createStore } from 'redux'
import { renderHook, act } from 'react-hooks-testing-library'
import { Provider as ProviderMock, useRedux } from '../../src/index.js'
describe('React', () => {
describe('hooks', () => {
describe('useRedux', () => {
let store
beforeEach(() => {
store = createStore(({ count } = { count: -1 }) => ({
count: count + 1
}))
})
it('selects the state and binds action creators', () => {
const { result } = renderHook(
() =>
useRedux(s => s.count, {
inc: () => ({ type: '' })
}),
{
wrapper: props => <ProviderMock {...props} store={store} />
}
)
expect(result.current[0]).toEqual(0)
act(() => {
result.current[1].inc()
})
expect(result.current[0]).toEqual(1)
})
})
})
})