Skip to content

Commit 4da1da3

Browse files
committed
chore(test): add test case, useSuspenseQuery, should use provided custom queryClient
1 parent a2110ef commit 4da1da3

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

packages/openapi-react-query/test/index.test.tsx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,41 @@ describe("client", () => {
223223
expect(await screen.findByText("Something went wrong")).toBeDefined();
224224
errorSpy.mockRestore();
225225
});
226+
227+
it("should use provided custom queryClient", async () => {
228+
const fetchClient = createFetchClient<paths>({ baseUrl });
229+
const client = createClient(fetchClient);
230+
const customQueryClient = new QueryClient({});
231+
232+
function Page() {
233+
const { data } = client.useSuspenseQuery(
234+
"get",
235+
"/blogposts/{post_id}",
236+
{
237+
params: {
238+
path: {
239+
post_id: "1",
240+
},
241+
},
242+
},
243+
{},
244+
customQueryClient,
245+
);
246+
return <div>data: {data?.title}</div>;
247+
}
248+
249+
useMockRequestHandler({
250+
baseUrl,
251+
method: "get",
252+
path: "/blogposts/:post_id",
253+
status: 200,
254+
body: { title: "Hello" },
255+
});
256+
257+
const rendered = render(<Page />);
258+
259+
await waitFor(() => rendered.findByText("data: Hello"));
260+
});
226261
});
227262

228263
describe("useMutation", () => {
@@ -290,6 +325,7 @@ describe("client", () => {
290325
return (
291326
<div>
292327
<button
328+
type="button"
293329
onClick={() =>
294330
mutation.mutate({
295331
body: {
@@ -316,7 +352,7 @@ describe("client", () => {
316352
body: { message: "Hello" },
317353
});
318354

319-
const rendered = render(<Page></Page>);
355+
const rendered = render(<Page />);
320356

321357
await rendered.findByText("data: null, status: idle");
322358

@@ -378,6 +414,7 @@ describe("client", () => {
378414
return (
379415
<div>
380416
<button
417+
type="button"
381418
onClick={() =>
382419
mutation.mutateAsync({
383420
body: {
@@ -404,7 +441,7 @@ describe("client", () => {
404441
body: { message: "Hello" },
405442
});
406443

407-
const rendered = render(<Page></Page>);
444+
const rendered = render(<Page />);
408445

409446
await rendered.findByText("data: null, status: idle");
410447

0 commit comments

Comments
 (0)