Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/tests/suspense.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { render, waitForElement, cleanup } from '@testing-library/react'
import * as React from 'react'

import { useQuery, queryCache } from '../index'
import { sleep } from './utils'

describe("useQuery's in Suspense mode", () => {
afterEach(() => {
queryCache.clear()
cleanup()
})

it('should not call the queryFn twice when used in Suspense mode', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove the "when used in Suspense mode" bit, woops.

Suggested change
it('should not call the queryFn twice when used in Suspense mode', async () => {
it('should not call the queryFn twice', async () => {

const queryFn = jest.fn()
queryFn.mockImplementation(() => sleep(10))

function Page() {
useQuery(['test'], queryFn, { suspense: true })

return 'rendered'
}

const rendered = render(
<React.Suspense fallback="loading">
<Page />
</React.Suspense>
)

await waitForElement(() => rendered.getByText('rendered'))

expect(queryFn).toHaveBeenCalledTimes(1)
})
})