Skip to content

Commit

Permalink
test(react-query): add test case for useQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed Mar 1, 2025
1 parent 5babd11 commit d17ebdd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/react-query/src/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6771,4 +6771,21 @@ describe('useQuery', () => {

consoleMock.mockRestore()
})

it('should console.error when there is no queryFn', () => {
const consoleErrorMock = vi.spyOn(console, 'error')
const key = queryKey()
function Example() {
useQuery({ queryKey: key })
return <></>
}
renderWithClient(queryClient, <Example />)

expect(consoleErrorMock).toHaveBeenCalledTimes(1)
expect(consoleErrorMock).toHaveBeenCalledWith(
`[${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`,
)

consoleErrorMock.mockRestore()
})
})

0 comments on commit d17ebdd

Please sign in to comment.