Open jtmueller opened 23 hours ago
This same error occurs when trying to unit-test pages that use protected$
and in this case the workaround of adding the missing import to the source page does not seem to help. Incidentally, how would you recommend simulating the signed-in state for such a test? Is there a way to provide a user to the SessionProvider?
src/route-tests/tasks.spec.tsx
ReferenceError: query is not defined
- /src/routes/tasks.tsx:12:20
- /src/route-tests/tasks.spec.tsx:7:31
Test file:
import { SessionProvider } from '@solid-mediakit/auth/client';
import { MetaProvider } from '@solidjs/meta';
import { Router } from '@solidjs/router';
import { render } from '@solidjs/testing-library';
import { expect, test } from 'vitest';
import Tasks from '~/routes/tasks';
test('renders', () => {
const { getByText } = render(() => <Tasks />, {
wrapper: props => (
<MetaProvider>
<SessionProvider>
<Router root={() => props.children} />
</SessionProvider>
</MetaProvider>
),
});
expect(getByText('Tasks for')).toBeInTheDocument();
});
Route file:
import { protected$ } from '@solid-mediakit/auth';
import { Title } from '@solidjs/meta';
// biome-ignore lint/correctness/noUnusedImports: temporary workaround for https://github.com/solidjs-community/mediakit/issues/144
import { query } from '@solidjs/router';
export default protected$(function Tasks(session$) {
return (
<>
<Title>Tasks</Title>
<main class="mx-auto p-4 text-center text-gray-700">
<h1 class="max-6-xs my-16 font-thin text-6xl text-sky-700 uppercase">
<div>Tasks for</div>
<div>{session$.user?.name}</div>
</h1>
</main>
</>
);
});
this is fixed in #142, just waiting for @OrJDev to merge the changeset
Oops, forgot to merge it. Merged now, ty for @ me
Released, please use latest version of the auth plugin and lmk if its fixed
Pages configured with the
protected$
function were failing to render, and the following error was showing in the logs:Using the
log
option forauthVite
shows me this generated code, where, indeed,query
is not defined:If I add this line to the source file, I get a warning about an unused import, but it fixes the problem:
import { query } from '@solidjs/router';
It looks like the fix is probably to change this already-injected line to also import
query
:import { redirect } from "@solidjs/router";