Skip to main content
The NuqsTestingAdapter provides a test environment for components that use nuqs hooks. It simulates URL state management without requiring a real router, making it easy to test components in isolation.

NuqsTestingAdapter

A React component that provides a testing context for nuqs hooks.

Props

string | Record<string, string> | URLSearchParams
Initial search params for the test. Can be provided as:
  • A query string: "?foo=bar&baz=qux"
  • A record object: { foo: "bar", baz: "qux" }
  • A URLSearchParams instance: new URLSearchParams("foo=bar")
Defaults to an empty string (no search params).
OnUrlUpdateFunction
A callback function invoked whenever the URL is updated. Useful for asserting URL changes in tests.The function receives a UrlUpdateEvent object containing:
  • searchParams: The new search params as a URLSearchParams instance
  • queryString: The rendered query string
  • options: The options used for the URL update
boolean
default:"false"
Controls whether the adapter stores search params in memory and updates them on each URL change.
  • false (default): The adapter is immutable. Search params remain frozen to the initial value. This encourages testing discrete units of behavior.
  • true: The adapter behaves like framework adapters, storing updates in memory so subsequent updates build on the previous state.
boolean
default:"true"
Whether to automatically reset the URL update queue after each update.In production, nuqs batches and throttles URL updates. This option controls whether the queue should be cleared after processing updates during tests.
boolean
default:"true"
Whether to clear the URL update queue when the adapter mounts.Since the update queue is a shared global, this option ensures test isolation by clearing the queue before each test. Set to false to preserve the queue between renders for testing edge cases.
number
default:"0"
Controls throttling behavior during tests.
  • 0 (default): No throttling - updates are immediate
  • 1: Production throttling (≥50ms)
  • Other values: Custom throttling factor
Most tests should use the default to avoid timing-related flakiness.
object
Default options to apply to all useQueryState hooks within this adapter.
Supported options:
  • shallow: Whether to use shallow routing (framework-specific)
  • scroll: Whether to scroll to top on URL updates
  • clearOnDefault: Whether to remove the key from URL when set to default value
  • limitUrlUpdates: Whether to limit the rate of URL updates
(search: URLSearchParams) => URLSearchParams
A function to process or transform search params before they’re used by hooks.
ReactNode
required
The components to render within the testing adapter context.

withNuqsTestingAdapter

A higher-order component that creates a wrapper function for testing libraries that support wrapper components (e.g., Testing Library, Vitest).

Signature

Parameters

Accepts all NuqsTestingAdapter props except children.

Returns

A wrapper component function that can be passed to testing library render methods.

Usage

Types

UrlUpdateEvent

The event object passed to the onUrlUpdate callback.
URLSearchParams
The new search params as a URLSearchParams instance. This is a copy that can be safely inspected or modified.
string
The rendered query string representation of the search params (e.g., "?foo=bar&baz=qux").
Required<AdapterOptions>
The options used for the URL update:
  • history: "push" | "replace" - The history method used
  • scroll: boolean - Whether to scroll to top
  • shallow: boolean - Whether shallow routing was used

OnUrlUpdateFunction

The type signature for the onUrlUpdate callback function.

Complete Example

Here’s a complete example testing a counter component:
counter.test.tsx

Direct Component Usage

You can also use NuqsTestingAdapter directly as a component:

See Also