Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(QwikCityMockProvider): custom loaders mocks
  • Loading branch information
alexismch committed Oct 29, 2025
commit 287f18dd4b2bae50d28028234795989fec57b02c
13 changes: 12 additions & 1 deletion packages/qwik-city/src/runtime/src/qwik-city-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
Editable,
EndpointResponse,
LoadedRoute,
LoaderConstructor,
MutableRouteLocation,
PageModule,
PreventNavigateCallback,
Expand Down Expand Up @@ -661,6 +662,10 @@ export interface QwikCityMockProps {
url?: string;
params?: Record<string, string>;
goto?: RouteNavigate;
loaders?: {
loader: LoaderConstructor;
data: any;
}[];
}

/** @public */
Expand All @@ -677,7 +682,13 @@ export const QwikCityMockProvider = component$<QwikCityMockProps>((props) => {
{ deep: false }
);

const loaderState = useSignal({});
const loaderState = useStore(
props.loaders?.reduce(
(acc, { loader, data }) => ({ ...acc, [(loader as any).__id]: data }),
{} as Record<string, any>
) ?? {},
{ deep: false }
);
const routeInternal = useSignal<RouteStateInternal>({ type: 'initial', dest: url });

const goto: RouteNavigate =
Expand Down