Skip to content

Commit 8a19f6c

Browse files
authored
Use jest node environment instead of mocking window object for SSR tests (TanStack#382)
* use jest node environment instead of mocking window object * clear query cache after each test * remove unnecessary test cleanup
1 parent f1ca0a1 commit 8a19f6c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/tests/useQuery-SSR.test.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import { cleanup } from '@testing-library/react'
1+
/**
2+
* @jest-environment node
3+
*/
4+
25
import React from 'react'
36
import { renderToString } from 'react-dom/server'
7+
import { usePaginatedQuery, queryCache } from '../index'
48

59
describe('useQuery SSR', () => {
6-
beforeEach(() => {
7-
const windowSpy = jest.spyOn(global, 'window', 'get')
8-
windowSpy.mockImplementation(() => undefined)
9-
})
10-
1110
afterEach(() => {
12-
cleanup()
11+
queryCache.clear()
1312
})
1413

1514
// See https://github.com/tannerlinsley/react-query/issues/70
1615
it('should not cache queries on server', async () => {
17-
// import react-query after mocking window
18-
const { usePaginatedQuery, queryCache } = require('../index')
19-
2016
function Page() {
2117
const [page, setPage] = React.useState(1)
2218
const { resolvedData } = usePaginatedQuery(

0 commit comments

Comments
 (0)