Skip to content

Fix/better error handling for hydrate #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -603,6 +603,15 @@
"contributions": [
"doc"
]
},
{
"login": "amovar18",
"name": "Kudaligi Amoghavarsha",
"avatar_url": "https://avatars.githubusercontent.com/u/59614577?v=4",
"profile": "https://github.com/amovar18",
"contributions": [
"maintenance"
]
}
],
"skipCi": true,
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@ library will instead be included as official additions to both `react-testing-li
([PR](https://github.com/callstack/react-native-testing-library/pull/923)) with the intention being
to provide a more cohesive and consistent implementation for our users.

Please be patient as we finalise these changes in the respective testing libraries.
In the mean time you can install `@testing-library/react@^13.1`
Please be patient as we finalise these changes in the respective testing libraries. In the mean time
you can install `@testing-library/react@^13.1`

## Table of Contents

@@ -263,6 +263,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://www.facebook.com/masoud.bonabi"><img src="https://avatars.githubusercontent.com/u/6429009?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Masious</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=masious" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Laishuxin"><img src="https://avatars.githubusercontent.com/u/56504759?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Laishuxin</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=Laishuxin" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/amovar18"><img src="https://avatars.githubusercontent.com/u/59614577?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kudaligi Amoghavarsha</b></sub></a><br /><a href="#maintenance-amovar18" title="Maintenance">🚧</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
16 changes: 11 additions & 5 deletions src/server/pure.ts
Original file line number Diff line number Diff line change
@@ -29,11 +29,17 @@ function createServerRenderer<TProps, TResult>(
if (container) {
throw new Error('The component can only be hydrated once')
} else {
container = document.createElement('div')
container.innerHTML = serverOutput
act(() => {
ReactDOM.hydrate(testHarness(renderProps), container!)
})
if (typeof document !== 'undefined') {
container = document.createElement('div')
container.innerHTML = serverOutput
act(() => {
ReactDOM.hydrate(testHarness(renderProps), container!)
})
} else {
throw new Error(
'Hydrate function can only be called in a client environment with a document available.'
)
}
}
},
rerender(props?: TProps) {