Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Document testing nuqs based hooks #795

Merged
Merged
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
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