Skip to content

Commit 7d3720c

Browse files
committed
Quick fix of testing-library#74
1 parent 3984ba9 commit 7d3720c

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

Diff for: src/index.js

+12-35
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
import React, { Suspense } from 'react'
2-
import { create, act } from 'react-test-renderer'
2+
import { act, create } from 'react-test-renderer'
33

4-
function TestHook({ callback, hookProps, children }) {
5-
children(callback(hookProps))
6-
return null
7-
}
8-
9-
class ErrorBoundary extends React.Component {
10-
constructor(props) {
11-
super(props)
12-
this.state = { hasError: false }
13-
}
14-
15-
static getDerivedStateFromError() {
16-
return { hasError: true }
17-
}
18-
19-
componentDidCatch(error) {
20-
this.props.onError(error)
21-
}
22-
23-
componentDidUpdate(prevProps) {
24-
if (this.props != prevProps && this.state.hasError) {
25-
this.setState({ hasError: false })
26-
}
27-
}
28-
29-
render() {
30-
return !this.state.hasError && this.props.children
4+
function TestHook({ callback, hookProps, onError, children }) {
5+
try {
6+
children(callback(hookProps))
7+
} catch (err) {
8+
onError(err)
319
}
10+
return null
3211
}
3312

3413
function Fallback() {
@@ -77,13 +56,11 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
7756

7857
const toRender = () =>
7958
wrapUiIfNeeded(
80-
<ErrorBoundary onError={setError}>
81-
<Suspense fallback={<Fallback />}>
82-
<TestHook callback={callback} hookProps={hookProps.current}>
83-
{setValue}
84-
</TestHook>
85-
</Suspense>
86-
</ErrorBoundary>
59+
<Suspense fallback={<Fallback />}>
60+
<TestHook callback={callback} hookProps={hookProps.current} onError={setError}>
61+
{setValue}
62+
</TestHook>
63+
</Suspense>
8764
)
8865

8966
let testRenderer

0 commit comments

Comments
 (0)