-
Hello, I have questions about react-query with playwright. ContextI'm using Playwright component test for testing react components. Experimental: components | Playwright But, I wrote below codes and run test so import MyComponet "./my-component";
import { test, expect } from "@playwright/experimental-ct-react";
import { QueryClientProvider, QueryClient } from "react-query";
test("test sample", async ({ mount, page }) => {
const queryClient = new QueryClient();
queryClient.setQueryData("key", { username: "foo"});
const component = await mount(
<QueryClientProvider client={queryClient}>
<MyComponent />
</QueryClientProvider>
);
}); I investigated react-query code and I found out that query/packages/query-core/src/queryCache.ts Lines 101 to 111 in 52acd78 On the other hand, when This function reference object recursively, so As workaround, I create wrapper component and import it, so well done. import { QueryClientProvider, QueryClient } from "react-query";
export default function QueryClientProviderWithData({ children }: { children: JSX.Element }) {
const queryClient = new QueryClient();
queryClient.setQueryData("key", { username: "foo"});
return (
<QueryClientProvider client={queryClient}>
{ children }
</QueryClientProvider>
)
} import MyComponet "./my-component";
import { test, expect } from "@playwright/experimental-ct-react";
import QueryClientProviderWithData from "./query-client-provider"
test("test sample", async ({ mount, page }) => {
const component = await mount(
<QueryClientProviderWithData>
<MyComponent />
</QueryClientProviderWithData>
);
}); Question
Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I don't see the circular reference. All that setQueryData does is to create an entry in the cache... your component looks fine if you only mount the component once, which is true for testing. Otherwise, I'd put the queryClient in state:
|
Beta Was this translation helpful? Give feedback.
I don't see the circular reference. All that setQueryData does is to create an entry in the cache...
your component looks fine if you only mount the component once, which is true for testing. Otherwise, I'd put the queryClient in state: