Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Doesn't work with Storybook Addon Next Router #86

Closed
brvnonascimento opened this issue Feb 1, 2022 · 1 comment
Closed

Doesn't work with Storybook Addon Next Router #86

brvnonascimento opened this issue Feb 1, 2022 · 1 comment

Comments

@brvnonascimento
Copy link

Doesn't work with Storybook Addon Next Router. Probably because it doesn't wrap it around a decorator and uses the addon field on main.js instead.

@yannbf
Copy link
Member

yannbf commented Feb 2, 2022

Hey @brvnonascimento thanks for opening an issue in this repo.
You're right! Addons might either expose decorators that you have to export in your preview.js file or they can expose presets which are automatically applied by Storybook. Unfortunately this library currently has a limitation which is the fact that it does not load presets from addons, so the decorator from storybook-addon-next-router is never picked up.

In order to work around this, you could inject the decorator from the addon, something that would look like this:

// setupTest.js
import { setGlobalConfig } from '@storybook/testing-react'
import * as globalConfig from '../.storybook/preview'
import { WithNextRouter } from "storybook-addon-next-router/dist/decorators"

setGlobalConfig({
  ...globalConfig,
  decorators: [
    ...globalConfig.decorators,
    WithNextRouter // not loaded automatically in preset, must add this manually for @storybook/testing-react to pick it up
  ]
})

And hopefully your problem is solved. It's not a great solution, especially because you rely on internals from the addon given that it does not export the decorator its the entry file.

I'm working on figuring the presets situation but that might take some time. Hope this helps!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants