Skip to content

Commit

Permalink
docs: Add mocking useLocation to docs (#6791)
Browse files Browse the repository at this point in the history
* add mocking-useLocation to how-to in docs

* Update mocking-useLocation.md

* move mocking-useLocation to testing

* Update docs/docs/testing.md

Co-authored-by: Dominic Saadi <[email protected]>

* Update docs/docs/testing.md

Co-authored-by: Dominic Saadi <[email protected]>
  • Loading branch information
2 people authored and github-actions committed Nov 4, 2022
1 parent 53b8fe4 commit 91ae7b6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ render(<Article article={ title: 'Foobar' } />, {
})
```
:::
### Mocking useLocation

To mock `useLocation` in your component tests, wrap the component with `LocationProvider`:

```jsx
import { LocationProvider } from '@redwoodjs/router'

render(
<LocationProvider location={{ pathname: '', search: '?cancelled=true' }}>
<Component />
</LocationProvider>
)
```

## Testing Custom Hooks

Expand Down

0 comments on commit 91ae7b6

Please sign in to comment.