Skip to content

Commit

Permalink
Fix skipped tests in ssr.spec.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed May 16, 2024
1 parent e726eeb commit e39eb77
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions test/integration/ssr.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ describe('New v8 serverState behavior', () => {

const Spinner = () => <div />

if (!IS_REACT_18) {
it('Dummy test for React 17, ignore', () => {})
return
}

const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {})

afterEach(() => {
vi.clearAllMocks()
consoleErrorSpy.mockClear()
})

afterAll(() => {
consoleErrorSpy.mockRestore()
})

it('Handles hydration correctly', async () => {
Expand Down Expand Up @@ -154,19 +155,21 @@ describe('New v8 serverState behavior', () => {
<Provider store={clientStore}>
<App />
</Provider>,
{
onRecoverableError: (error, errorInfo) => {
console.error('Hydration error')
},
},
)
})

const [lastCall = []] = consoleError.mock.calls.slice(-1)
const [errorArg] = lastCall
expect(errorArg).toBeInstanceOf(Error)
expect(/There was an error while hydrating/.test(errorArg.message)).toBe(
true,
)
expect(consoleErrorSpy).toHaveBeenCalledOnce()

Check failure on line 166 in test/integration/ssr.spec.tsx

View workflow job for this annotation

GitHub Actions / Run local tests against build artifact (React ^18)

test/integration/ssr.spec.tsx > New v8 serverState behavior > Handles hydration correctly

AssertionError: expected "error" to be called once, but got 8 times ❯ test/integration/ssr.spec.tsx:166:29

expect(consoleErrorSpy).toHaveBeenLastCalledWith('Hydration error')

vi.resetAllMocks()
consoleErrorSpy.mockClear()

expect(consoleError.mock.calls.length).toBe(0)
expect(consoleErrorSpy).not.toHaveBeenCalled()

document.body.removeChild(rootDiv)

Expand All @@ -187,7 +190,7 @@ describe('New v8 serverState behavior', () => {
)
})

expect(consoleError.mock.calls.length).toBe(0)
expect(consoleErrorSpy).not.toHaveBeenCalled()

// Buttons should both exist, and have the updated count due to later render
const button1 = rtl.screen.getByText('useSelector:Hydrated. Count: 1')
Expand Down

0 comments on commit e39eb77

Please sign in to comment.