-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathindex.js
40 lines (33 loc) · 999 Bytes
/
index.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
import React from 'react'
import { render, cleanup, act } from 'react-testing-library'
function TestHook({ callback, hookProps, children }) {
children(callback(hookProps))
return null
}
function renderHook(callback, { initialProps, ...options } = {}) {
const result = { current: null }
const hookProps = { current: initialProps }
const toRender = () => (
<TestHook callback={callback} hookProps={hookProps.current}>
{(res) => {
result.current = res
}}
</TestHook>
)
const { unmount, rerender: rerenderComponent } = render(toRender(), options)
return {
result,
unmount,
rerender: (newProps = hookProps.current) => {
hookProps.current = newProps
rerenderComponent(toRender())
}
}
}
function testHook(...args) {
console.warn(
'`testHook` has been deprecated and will be removed in a future release. Please use `renderHook` instead.'
)
return renderHook(...args)
}
export { renderHook, cleanup, act, testHook }