Skip to content

Commit 136131b

Browse files
author
Joe
committed
feat: add ssr test to repro testing-library#605
1 parent 877f6e8 commit 136131b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/server/__tests__/ssr.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
import { useState } from 'react'
5+
import { renderHook, act } from '..'
6+
7+
// This verifies that renderHook can be called in
8+
// a SSR-like environment.
9+
describe('ssr', () => {
10+
function useLoading() {
11+
if (typeof window !== 'undefined') {
12+
const [loading, setLoading] = useState(false)
13+
return { loading, setLoading }
14+
}
15+
}
16+
17+
test('should not throw ReferenceError', () => {
18+
const { result, hydrate } = renderHook(() => useLoading())
19+
20+
hydrate()
21+
22+
act(() => result?.current?.setLoading(true))
23+
24+
expect(result?.current?.loading).toBe(true)
25+
})
26+
})

0 commit comments

Comments
 (0)