Skip to content

Commit

Permalink
docs: document testing nuqs based hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianvitterso committed Dec 7, 2024
1 parent 2779419 commit 8a605bd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/docs/content/docs/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
}}>
```

When testing hooks that rely on nuqs' `useQueryState(s){:ts}` with React Testing Library's
[`renderHook{:ts}`](https://testing-library.com/docs/react-testing-library/api/#renderhook) function,
you can use the `withNuqsTestingAdapter{:ts}` as a wrapper component passed into the
`renderHook{:ts}` call.

```tsx
const { result } = renderHook(() => useMyNiceHook(), { wrapper: withNuqsTestingAdapter({
searchParams: { q: 'hello-world' }
}) })
```


- `onUrlUpdate{:ts}`, a function that will be called when the URL is updated
by the component. It receives an object with:
- the new search params as an instance of `URLSearchParams{:ts}`
Expand Down

0 comments on commit 8a605bd

Please sign in to comment.