Skip to content

Commit

Permalink
add example to reproduce defect of serializeQueryArgs with skipToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Themezv committed Nov 12, 2024
1 parent 24286f1 commit 9384f72
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ const api = createApi({
return true
},
}),
queryWithDeepArg: build.query<string, { param: {nested: string} }>({
query: ({param: {nested}}) => nested,
serializeQueryArgs: ({queryArgs}) => {
return queryArgs.param.nested
}
}),
}),
})

Expand Down Expand Up @@ -667,6 +673,12 @@ describe('hooks tests', () => {
await screen.findByText('ID: 3')
})

test(`useQuery shouldn't call args serialization if request skipped`, async () => {
expect(() => renderHook(() => api.endpoints.queryWithDeepArg.useQuery(skipToken), {
wrapper: storeRef.wrapper,
})).not.toThrow()

Check failure on line 679 in packages/toolkit/src/query/tests/buildHooks.test.tsx

View workflow job for this annotation

GitHub Actions / Test against dist (20.x)

src/query/tests/buildHooks.test.tsx > hooks tests > useQuery > useQuery shouldn't call args serialization if request skipped

AssertionError: expected [Function] to not throw an error but 'TypeError: Cannot read properties of …' was thrown - Expected: undefined + Received: "TypeError: Cannot read properties of undefined (reading 'nested')" ❯ src/query/tests/buildHooks.test.tsx:679:15
})

test(`useQuery gracefully handles bigint types`, async () => {
function ItemList() {
const [pageNumber, setPageNumber] = useState(0)
Expand Down

0 comments on commit 9384f72

Please sign in to comment.