Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/react-hooks-testing-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.0.0
Choose a base ref
...
head repository: testing-library/react-hooks-testing-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.0.1
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on May 20, 2022

  1. chore(docs): Update README.md (#843)

    The documentation isnt clear.
    fotoflo authored May 20, 2022
    Copy the full SHA
    efd262c View commit details

Commits on Jun 18, 2022

  1. fix(server): remove act around server renderer to fix support for old…

    …er versions of react
    
    * refactor(server/pure): remove unnecessary type annotation
    
    * feat: add ssr.test.ts
    
    This adds a new test to verify that renderHook can be called in an
    SSR-like environment based on the changes implemented in #607.
    
    * chore: update contributors table
    
    * refactor: remove act call in render in sever/pure
    
    @mpeyper explained how this `act` call in server rendering is not really
    necessary so we can remove it.
    jsjoeio authored Jun 18, 2022
    Copy the full SHA
    e2461ca View commit details
Showing with 28 additions and 10 deletions.
  1. +2 −1 .all-contributorsrc
  2. +2 −1 README.md
  3. +18 −0 src/__tests__/ssr.test.ts
  4. +6 −8 src/server/pure.ts
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -145,7 +145,8 @@
"avatar_url": "https://avatars3.githubusercontent.com/u/3806031?v=4",
"profile": "https://jsjoe.io",
"contributions": [
"tutorial"
"tutorial",
"test"
]
},
{
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ library will instead be included as official additions to both `react-testing-li
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`

## Table of Contents

@@ -197,7 +198,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/VinceMalone"><img src="https://avatars0.githubusercontent.com/u/2516349?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vince Malone</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=VinceMalone" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/doppelmutzi"><img src="https://avatars1.githubusercontent.com/u/4130968?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian Weber</b></sub></a><br /><a href="#blog-doppelmutzi" title="Blogposts">📝</a></td>
<td align="center"><a href="https://gillchristian.xyz"><img src="https://avatars2.githubusercontent.com/u/8309423?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christian Gill</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=gillchristian" title="Documentation">📖</a></td>
<td align="center"><a href="https://jsjoe.io"><img src="https://avatars3.githubusercontent.com/u/3806031?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JavaScript Joe</b></sub></a><br /><a href="#tutorial-jsjoeio" title="Tutorials">✅</a></td>
<td align="center"><a href="https://jsjoe.io"><img src="https://avatars3.githubusercontent.com/u/3806031?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JavaScript Joe</b></sub></a><br /><a href="#tutorial-jsjoeio" title="Tutorials">✅</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=jsjoeio" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center"><a href="http://frontstuff.io"><img src="https://avatars1.githubusercontent.com/u/5370675?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sarah Dayan</b></sub></a><br /><a href="#platform-sarahdayan" title="Packaging/porting to new platform">📦</a></td>
18 changes: 18 additions & 0 deletions src/__tests__/ssr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @jest-environment node
*/
import { useState } from 'react'

// This verifies that renderHook can be called in
// a SSR-like environment.
describe('renderHook', () => {
function useLoading() {
const [loading, setLoading] = useState(false)
return { loading, setLoading }
}
runForRenderers(['server'], ({ renderHook }) => {
test('should not throw in SSR environment', () => {
expect(() => renderHook(() => useLoading())).not.toThrowError('document is not defined')
})
})
})
14 changes: 6 additions & 8 deletions src/server/pure.ts
Original file line number Diff line number Diff line change
@@ -13,19 +13,17 @@ function createServerRenderer<TProps, TResult>(
) {
let renderProps: TProps | undefined
let container: HTMLDivElement | undefined
let serverOutput: string = ''
let serverOutput = ''
const testHarness = createTestHarness(rendererProps, wrapper, false)

return {
render(props?: TProps) {
renderProps = props
act(() => {
try {
serverOutput = ReactDOMServer.renderToString(testHarness(props))
} catch (e: unknown) {
rendererProps.setError(e as Error)
}
})
try {
serverOutput = ReactDOMServer.renderToString(testHarness(props))
} catch (e: unknown) {
rendererProps.setError(e as Error)
}
},
hydrate() {
if (container) {