-
Notifications
You must be signed in to change notification settings - Fork 231
Description
react-hooks-testing-libraryversion: 0.5.0react-testing-libraryversion: 7.0.0reactversion: 16.8.6nodeversion: 10.12.0yarnversion: 1.13.0
Relevant code or config:
const { 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]`
)What you did:
I had to edit the following line and removed the state check to make the test passing.
What happened:
Without that modification, the result.error after the rerender is undefined
Reproduction:
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
Problem description:
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.
Suggested solution:
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.