Closed
Description
Is there a best practice or a good way to test code that has setup in a parent layout. For example, I used svelte kit latest sample and then tested a page that was using svelte query provider defined in the parent layout.
import { render, screen } from '@testing-library/svelte';
import '@testing-library/jest-dom/vitest';
import { describe, expect, test } from 'vitest';
import Page from './+page.svelte';
describe('/+page.svelte', () => {
test('should render h1', () => {
render(Page);
expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument();
});
});
This fails with:
FAIL client src/routes/status/page.svelte.test.ts > /+page.svelte > should render h1
Error: No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?
❯ getQueryClientContext node_modules/@tanstack/svelte-query/dist/context.js:7:15
5| const client = getContext(_contextKey);
6| if (!client) {
7| throw new Error('No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?');
| ^
8| }
I'm also noticing other things like dynamic env's are causing issues too.
Metadata
Metadata
Assignees
Labels
No labels