Skip to content

Commit 8a605bd

Browse files
docs: document testing nuqs based hooks
1 parent 2779419 commit 8a605bd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/docs/content/docs/testing.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
128128
}}>
129129
```
130130

131+
When testing hooks that rely on nuqs' `useQueryState(s){:ts}` with React Testing Library's
132+
[`renderHook{:ts}`](https://testing-library.com/docs/react-testing-library/api/#renderhook) function,
133+
you can use the `withNuqsTestingAdapter{:ts}` as a wrapper component passed into the
134+
`renderHook{:ts}` call.
135+
136+
```tsx
137+
const { result } = renderHook(() => useMyNiceHook(), { wrapper: withNuqsTestingAdapter({
138+
searchParams: { q: 'hello-world' }
139+
}) })
140+
```
141+
142+
131143
- `onUrlUpdate{:ts}`, a function that will be called when the URL is updated
132144
by the component. It receives an object with:
133145
- the new search params as an instance of `URLSearchParams{:ts}`

0 commit comments

Comments
 (0)