Skip to content

Commit 887820c

Browse files
authored
test(react-query): add test case for useQuery (#8729)
1 parent 4fb781f commit 887820c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/react-query/src/__tests__/useQuery.test.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -6771,4 +6771,21 @@ describe('useQuery', () => {
67716771

67726772
consoleMock.mockRestore()
67736773
})
6774+
6775+
it('should console.error when there is no queryFn', () => {
6776+
const consoleErrorMock = vi.spyOn(console, 'error')
6777+
const key = queryKey()
6778+
function Example() {
6779+
useQuery({ queryKey: key })
6780+
return <></>
6781+
}
6782+
renderWithClient(queryClient, <Example />)
6783+
6784+
expect(consoleErrorMock).toHaveBeenCalledTimes(1)
6785+
expect(consoleErrorMock).toHaveBeenCalledWith(
6786+
`[${queryClient.getQueryCache().find({ queryKey: key })?.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,
6787+
)
6788+
6789+
consoleErrorMock.mockRestore()
6790+
})
67746791
})

0 commit comments

Comments
 (0)