Skip to content

Commit

Permalink
test(connectObservable): add test combining ErrorBoundary and Suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva authored and josepot committed Jul 9, 2020
1 parent 869be66 commit 08cd48e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/connectObservable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,35 @@ describe("connectObservable", () => {
)
})

it("allows errors to be caught in error boundaries with suspense", () => {
const errStream = new Subject()
const [useError] = connectObservable(errStream)

const ErrorComponent = () => {
const value = useError()

return <>{value}</>
}

const errorCallback = jest.fn()
render(
<TestErrorBoundary onError={errorCallback}>
<Suspense fallback={<div>Loading...</div>}>
<ErrorComponent />
</Suspense>
</TestErrorBoundary>,
)

componentAct(() => {
errStream.error("controlled error")
})

expect(errorCallback).toHaveBeenCalledWith(
"controlled error",
expect.any(Object),
)
})

it("doesn't throw errors on components that will get unmounted on the next cycle", () => {
const valueStream = new BehaviorSubject(1)
const [useValue, value$] = connectObservable(valueStream)
Expand Down

0 comments on commit 08cd48e

Please sign in to comment.