react-hooks-testing-library version: 0.5.0react-testing-library version: 7.0.0react version: 16.8.6node version: 10.12.0yarn version: 1.13.0const { result, rerender } = renderHook(
({ second }) => {
const obj = second ? { foo: "brr", baz: "new" } : { foo: "baz" }
return useAsObservableSource(obj)
},
{ initialProps: { second: false } }
)
rerender({ second: true })
expect(result.error).toMatchInlineSnapshot(
`[Error: the shape of objects passed to useAsObservableSource should be stable]`
)
I had to edit the following line and removed the state check to make the test passing.
Without that modification, the result.error after the rerender is undefined
Failing test: https://travis-ci.org/mobxjs/mobx-react-lite/builds/533269870#L484
Source code: https://github.com/mobxjs/mobx-react-lite/blob/no-observable-source-failing/test/useAsObservableSource.test.tsx#L344
I am not entirely sure what's happening there. The error is caught within componentDidCatch, but the resultContainer.setError is not called at all. It's really strange.
I think that for the purpose of testing the children should be always returned from ErrorBoundary. React will remount it anyway, so there is no problem of endless loop. The state.hasError is more useful in real apps where you want to inform a user about the problem and offer some way out of it.
Edit: Later I realized my change has broken other tests, so it's the not correct way either.
I'll take a look when I get to work. I've previously stated (#50) that I'm just going to remove the error boundary as it seems to be causing more issues than it was helping me solve (not catching promises for Suspense).
I'll see if going back to a try/catch makes this work as expected.
Yes, you are right, the try/catch fixes this particular scenario perfectly.
I've pushed the changes I've made 鈽濓笍 to the fork if you want to base the work on that.
I've brought in your changes with a slight adjustment to fix the Suspense tests. I've also added you as a contributor to the README, but if you don't want that let me know and I'll revert that commit.