nuqs
Version:
79 lines (78 loc) • 2.37 kB
TypeScript
import "../defs-DVjFg2Y1.js";
import { a as AdapterInterface, n as AdapterProps, o as AdapterOptions } from "../context-BE-tNWKb.js";
import { ReactElement, ReactNode } from "react";
//#region src/adapters/testing.d.ts
type UrlUpdateEvent = {
searchParams: URLSearchParams;
queryString: string;
options: Required<AdapterOptions>;
};
type OnUrlUpdateFunction = (event: UrlUpdateEvent) => void;
type TestingAdapterProps = Pick<AdapterInterface, "autoResetQueueOnUpdate"> & {
/**
* An initial value for the search params.
*/
searchParams?: string | Record<string, string> | URLSearchParams;
/**
* A function that will be called whenever the URL is updated.
* Connect that to a spy in your tests to assert the URL updates.
*/
onUrlUpdate?: OnUrlUpdateFunction;
/**
* Internal: enable throttling during tests.
*
* @default 0 (no throttling)
*/
rateLimitFactor?: number;
/**
* Internal: Whether to reset the url update queue on mount.
*
* Since the update queue is a shared global, each test clears
* it on mount to avoid interference between tests.
*
* @default true
*/
resetUrlUpdateQueueOnMount?: boolean;
/**
* If true, the adapter will store the search params in memory and
* update that memory on each updateUrl call, to simulate a real adapter.
*
* Otherwise, the search params will be frozen to the initial value.
*
* @default false
*/
hasMemory?: boolean;
children: ReactNode;
} & AdapterProps;
declare function NuqsTestingAdapter({
resetUrlUpdateQueueOnMount,
autoResetQueueOnUpdate,
defaultOptions,
processUrlSearchParams,
rateLimitFactor,
hasMemory,
onUrlUpdate,
children,
searchParams: initialSearchParams
}: TestingAdapterProps): ReactElement;
/**
* A higher order component that wraps the children with the NuqsTestingAdapter
*
* It allows creating wrappers for testing purposes by providing only the
* necessary props to the NuqsTestingAdapter.
*
* Usage:
* ```tsx
* render(<MyComponent />, {
* wrapper: withNuqsTestingAdapter({ searchParams: '?foo=bar' })
* })
* ```
*/
declare function withNuqsTestingAdapter(props?: Omit<TestingAdapterProps, "children">): ({
children
}: {
children: ReactNode;
}) => ReactElement;
//#endregion
export { NuqsTestingAdapter, OnUrlUpdateFunction, UrlUpdateEvent, withNuqsTestingAdapter };
//# sourceMappingURL=testing.d.ts.map