Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/hot-bears-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-router-mock": minor
---

Updated `MemoryRouterProvider` to support Next 13.5
3 changes: 3 additions & 0 deletions MemoryRouterProvider/next-13.5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "../../dist/MemoryRouterProvider/next-13.5"
}
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,17 @@ module.exports = {
};
```

This ensures that all your components that use `useRouter` will just work in Storybook.
This ensures that all your components that use `useRouter` will work in Storybook. If you also need to test `next/link`, please see the section [Example: **`next/link` with Storybook**](#example-nextlink-with-storybook).

### Storybook Example

In your individual stories, you might want to mock the current URL (eg. for testing an "ActiveLink" component), or you might want to log `push/replace` actions. You can do this by wrapping your stories with the `<MemoryRouterProvider>` component like so:
In your individual stories, you might want to mock the current URL (eg. for testing an "ActiveLink" component), or you might want to log `push/replace` actions. You can do this by wrapping your stories with the `<MemoryRouterProvider>` component.

```jsx
// ActiveLink.story.jsx
import { action } from '@storybook/addon-actions';
import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider';
import { MemoryRouterProvider }
from 'next-router-mock/MemoryRouterProvider/next-13';
import { ActiveLink } from './active-link';

export const ExampleStory = () => (
Expand All @@ -125,6 +126,13 @@ export const ExampleStory = () => (
);
```

> Be sure to import from **a matching Next.js version**:
> ```
> import { MemoryRouterProvider }
> from 'next-router-mock/MemoryRouterProvider/next-13.5';
> ```
> Choose from `next-13.5`, `next-13`, `next-12`, or `next-11`.

The `MemoryRouterProvider` has the following optional properties:

- `url` (`string` or `object`) sets the current route's URL
Expand Down Expand Up @@ -193,7 +201,7 @@ In Storybook, you must wrap your component with the `<MemoryRouterProvider>` com
import NextLink from 'next/link';
import { action } from '@storybook/addon-actions';

import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider';
import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider/next-13.5';

export const ExampleStory = () => (
<MemoryRouterProvider url="/initial">
Expand Down
Loading