尽管我已将测试包装在 QueryClientProvider 中,但我不断收到错误 [错误:未设置 QueryClient,请使用 QueryClientProvider 设置一个]。我做错了什么。
describe("Selector", () => {
beforeEach(() => {
const queryClient = new QueryClient();
render(
<QueryClientProvider client={queryClient}>
<ErrorBoundary FallbackComponent={({ error }) => <div>Something went wrong: {error.message}</div>}>
<Selector content={content} setLanguageCallback={() => {}} />
</ErrorBoundary>
</QueryClientProvider>,
);
screen.debug();
});
it("Is there a hello test text", () => {
expect(screen.getByText("Hello")).toBeInTheDocument();
});
});
这对我有用
const queryClient = new QueryClient();
describe('Home', () => {
test('renders without crashing', () => {
render(
<QueryClientProvider client={queryClient}>
<SnackbarProvider>
<Provider store={store}>
<Home />
</Provider>
</SnackbarProvider>
</QueryClientProvider>
);
const myEleme = screen.getByText('Sign in');
expect(myEleme).toBeInTheDocument();
});
});