Skip to content

Commit

Permalink
feat: add ssr test to repro testing-library#605
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe committed Feb 20, 2022
1 parent 877f6e8 commit 136131b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/server/__tests__/ssr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @jest-environment node
*/
import { useState } from 'react'
import { renderHook, act } from '..'

// This verifies that renderHook can be called in
// a SSR-like environment.
describe('ssr', () => {
function useLoading() {
if (typeof window !== 'undefined') {
const [loading, setLoading] = useState(false)
return { loading, setLoading }
}
}

test('should not throw ReferenceError', () => {
const { result, hydrate } = renderHook(() => useLoading())

hydrate()

act(() => result?.current?.setLoading(true))

expect(result?.current?.loading).toBe(true)
})
})

0 comments on commit 136131b

Please sign in to comment.