Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/contexts/TestContext.tsx
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
8
import { render } from "@testing-library/react";
9
import { FC } from "react";
10
11
// Add necessary contexts for tests to run
12
export const TestContext: FC = ({ children }) => {
13
const queryClient = new QueryClient({
14
defaultOptions: {
15
queries: {
16
retry: false,
17
},
18
},
19
});
20
21
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
22
};
23
24
type RenderParameters = Parameters<typeof render>;
25
type RenderReturn = ReturnType<typeof render>;
26
27
// render() with <TestContext> wrapper
28
export const renderWithContext = (ui: RenderParameters["0"], options?: RenderParameters["1"]): RenderReturn => {
29
return render(<TestContext>{ui}</TestContext>, options);
30
};
31
32