Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
madshall committed Jun 6, 2024
1 parent 9b67e7e commit b2ad56d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/graphql-hooks/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function useQuery<
setCalledDuringSSR(true)
}

const { client: clientFromOpts, allOptsToStringify } = allOpts
const { client: clientFromOpts, ...allOptsToStringify } = allOpts
const stringifiedAllOpts = JSON.stringify(allOptsToStringify)
React.useEffect(() => {
if (allOpts.skip) {
Expand Down
11 changes: 11 additions & 0 deletions packages/graphql-hooks/test-jsdom/unit/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ describe('useQuery', () => {
expect(mockClient2.ssrPromises[0]).resolves.toBe('data')
})

it('does not run when client headers change', () => {
const { rerender } = renderHook(() => useQuery(TEST_QUERY, { client: mockClient }), {
wrapper: Wrapper
})
mockClient.headers = {
trace_id: '123'
}
rerender()
expect(mockQueryReq).toHaveBeenCalledTimes(1)
})

describe('skip option', () => {
it('should skip query if `skip` is `true`', () => {
const queryReqMock = jest.fn()
Expand Down

0 comments on commit b2ad56d

Please sign in to comment.