mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-05 09:57:14 +00:00
test: wrap renderWithProviders in QueryClientProvider
The upstream PR branch's copy of this helper already wraps QueryClientProvider (needed by any test rendering a component that uses react-query), but this fork's own main never picked that up -- until the just-ported rule-form-geodata-tags.test.tsx became the first test here to render a component (RuleFormModal) whose hooks call useQuery, failing immediately with "No QueryClient set". Backward compatible: all 12 existing callers pass unchanged since QueryClientProvider is a no-op for components that don't touch react-query. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import type { ReactElement } from 'react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
import { ThemeProvider } from '@/hooks/useTheme';
|
||||
|
||||
export function renderWithProviders(ui: ReactElement) {
|
||||
return render(<ThemeProvider>{ui}</ThemeProvider>);
|
||||
export function makeTestQueryClient() {
|
||||
return new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
}
|
||||
|
||||
export function renderWithProviders(ui: ReactElement, options?: { queryClient?: QueryClient }) {
|
||||
const queryClient = options?.queryClient ?? makeTestQueryClient();
|
||||
return render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ThemeProvider>{ui}</ThemeProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
export function fieldLabels(): string[] {
|
||||
|
||||
Reference in New Issue
Block a user